Posts

javascript - How to read configuration set in option page from content_scripts of Chrome extension? -

using localstorage, try store users configs, , works well. // in options_page localstorage.setitem('mykey',someval); but it's difficult read configs content_scripts (´・ω・`) localstorage.getitem('mykey'); // because different 'window' scope i'm making using runtime.sendmessage // in content_scripts chrome.runtime.sendmessage(null, {purpose:'getconfig',configkey:'mykey'}, function(confhere){ // action } ); i think it's complex!! (and using 'chrome.storage' requires permission, ugly) there way read configs content_scripts of chrome extension? content scripts run within context of pages sharing dom , not extension. so, content script trying read localstorage read localstorage of page, , not extension. the way proposed correct , far know best way access setting info in content script. so, when content script created send message background settings (as have done) , in background add list...

c# - How to convert an arbitrary object to enum? -

i have object. either long or string , simplify code let's assume that. i have create method tries convert object provided enum. so: public object toenum(type enumtype, object value) { if(enumtype.isenum) { if(enum.isdefined(enumtype, value)) { var val = enum.parse(enumtype, (string)value); return val; } } return null; } with strings works well. numbers causes problems, because default underlying type enum int , not long , isdefined throws argumentexception . of course can many checks, conversions or try-catches. what want have clean , small code that. ideas how make readable , simple? it feels me want handle 3 cases: input right type strings integers in various types i believe want valid input: public object toenum(type enumtype, object value) { if (value == null) { throw new argumentnullexception("value"); } if (enumtype == null) { throw...

titanium - Keep the code together or split up? -

i building app in titanium studios, it's childrens sound app. going have 1 sound/animal per window. better split code(one(1) window per js-file) on different js files or should keep code in same app.js? also; first question on here bear me. all dependa how want design app, how code reused between windows , how complex it. in general it's split code between files wait until will.be big enouhh refactoring.

regex - Ensuring a matched string contains at least one uppercase character -

given string "this uppercase test url ( http://www.somedomain.com/some/path ). lowercase test url ( http://www.somedomain.com/some/path )" i have regex find urls: \(http://www.somedomain.com/(.*?)\) can amend return url if contains uppercase character in path? you can put positive lookahead check uppercase character: (?=\s*[a-z])\(http://www.somedomain.com/(.*?)\) ^^^^^^^^^^^^ it'll make sure there's @ least 1 uppercase character in string. regex101 demo if want make sure 'check' remains within brackets, can use this: \((?=[^)\s]*[a-z])http://www.somedomain.com/(.*?)\) regex101 demo

php - Wordpress menu: Remove list-items and apply ".current-menu-item" to anchor tag -

title says all. in short, how make wp_nav_menu(); output this: <nav> <a>menu item</a> <a class="current-menu-item">menu item</a> <a>menu item</a> <a>menu item</a> <a>menu item</a> </nav> i read http://css-tricks.com/snippets/wordpress/remove-li-elements-from-output-of-wp_nav_menu/ removes unordered list , list-items. but removing <li> s removes useful .current-menu-item class when you're on particular page. how class show on anchor tag instead? you can edit output via first parameter of function wp_nav_menu($args); . $args = array( 'theme_location' => '', 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' ...

c# - Can I create or generate an invalid System.Guid in .Net? -

can somehow invalid system.guid object created in .net (visual basic or c#). know guid.empty method not searching for. example invalid symbols or spaces or being short or longer valid 1 etc. thanks! can guid created invalid symbols or spaces or being short or longer valid 1 etc? no - guid 128-bit number can represented in 4 groups of hexadecimal numbers. there's no way string representation of guid contain other 32 hex characters (and 3 dashes). you can create string not represent valid guid , there's no way put guid object.

java - Formatting miliseconds to hh:mm:ss format -

i having miliseconds value , want display time subtracting 5 minutes current miliseconds value in hh:mm:ss format. code string str = string.format("%02d:%02d:%02d", timeunit.milliseconds.tohours((cal.gettimeinmillis()-300000)), timeunit.milliseconds.tominutes(cal.gettimeinmillis()-300000) - timeunit.hours.tominutes(timeunit.milliseconds.tohours(cal.gettimeinmillis()-300000)), timeunit.milliseconds.toseconds(cal.gettimeinmillis()-300000) - timeunit.minutes.toseconds(timeunit.milliseconds.tominutes(cal.gettimeinmillis()-300000))); toast.maketext(getapplicationcontext(), "alarm set."+str, toast.length_long).show() output now alarm set. 386467:25:00 output required alarm set. 07:25:00 as see minutes , seconds getting retrieved quiet right there's problem hours . p.s 1.i referred ...