Posts

Showing posts from January, 2013

In Haskell, what is the reason for needing to convert from Data.Text.Internal? -

text.regex.tdfa.text 1 provides instances regexlike regex text using internal text types. can instances of classes data.text.lazy derived instances of data.text.internal ? how can improve code? import qualified data.text.lazy t import text.regex.tdfa import text.regex.base.context() import text.regex.base.regexlike() import text.regex.tdfa.text import data.function (on) (<?>) :: t.text -> t.text -> bool (<?>) = on (=~) t.tostrict i might missing something, seems have missed the module containing lazy text instances regex-tdfa classes . if that's what's happening, need change import text.regex.tdfa.text to import text.regex.tdfa.text.lazy note called text in module data.text.internal same called text in data.text -- i.e., it's "strict" text . lazy text type defined in different internal module (basically specialized list of strict texts.) it's not though these 2 ways of viewing same thing, if that's

android - How to get a DialogPreference to popup so that I can create a wizard-style UI? -

i have number of preferences need set , want guide user through flow popping individual preference dialogs (listpreference, edittextpreference etc.), 1 @ time can create wizard-style ui . as user fills in pref, closes , next 1 opens up. as far know, user has click on preference dialog popup. is there way programmatically ? you can use onitemclick perform click on preference item. get preference position preference order. int position = findpreference("language").getorder(); language preference key. then, onitemclick on preference item position. getpreferencescreen().onitemclick(null,null,position,0);

ruby on rails - Trouble Getting Twitter Gem To Work - Giving Undefined Method Errors -

i following along documentation twitter gem , trying results, getting following error: undefined method `sample' nil:nilclass i've put in config/initializers/twitter_credentials.rb (my keys , tokens filled in app) @client = twitter::streaming::client.new |config| config.consumer_key = "your_consumer_key" config.consumer_secret = "your_consumer_secret" config.access_token = "your_access_token" config.access_token_secret = "your_access_secret" end here bits controller: require 'twitter' class staticpagescontroller < applicationcontroller def home @tweets = array.new @client.sample |object| @tweets << object.text if object.is_a?(twitter::tweet) end end end this in view: <% @tweets |tweet| %> <%= tweet.text %> <% end %> and of course, in gemfile: gem 'twitter' why getting error? the problem was referencing using in

Using Grails Transaction when saving two different domain object in one shot -

i have domain classes need updated @ same time, want use transaction in order allow changes both or neither. example : i have 2 different domain classes (user, , follow) user currentuser =.. user targetuser = .. follow followuser = .. targetuser.follower = targetuser.follower + 1 currentuser.follow = currentuser.follow + 1 targetuser.save(flush:true) currentuser.save(flush:true) followuser.save(flush:true) i want of happen or if 1 fails none of happen , gets rolled back. how can in grails ? saw domainobject.withtransaction, have 2 different domain, should nested ? the proper solution move transactional code service. documentation outlines how create , use services controllers. that's proper solution. however, that's not way. have seen there ability run code within transaction scope using withtransaction. example (directly documentation ): account.withtransaction { status -> def source = account.get(params.from) def dest = account.get(params

javascript - jQuery .getJSON() URL Error -

this json data retrieved when use (method redacted) method: [{ "group_option": { "optionsid": "28", "menugroupid": "6", "group_options_name": "select 2 (2) sides :", "menu_group_option_information": null, "menu_group_option_min_selected": "0", "menu_group_option_max_selected": "2", "fdateadded": "2014-01-25 08:29:20", "group_option_items": [{ "item": { "optionitemid": "69", "menu_item_option_name": "mexican rice", "menu_item_option_additional_cost": null } }, { "item": { "optionitemid": "70", "menu_item_option_name": "refried beans",

pipeline - Unix tr command to convert lower case to upper AND upper to lower case -

so searching around , using command tr can convert lower case upper case , vice versa. there way both @ once? so: $ tr '[:upper:]' '[:lower:]' or $ tr a-z a-z will turn: "hello world abc" "hello world abc" but want do: "hello world abc" please help! =) this looking for: tr '[:upper:][:lower:]' '[:lower:][:upper:]'

c++ - Access QVector element index by its content -

i have qvector of qstrings , want remove element content, don't know how find index of it. know how can remove it? don't want iterate on , compare content value. my qvector declared follows: qvector <qstring> user_valid; and want remove content, example element value "marigold": user_valid.remove(user_valid.find("marigold"); thank in advance! ok, following if you: use qstringlist instead of qvector<qstring> has convenience methods can useful you; more common , hence comprehensive. spare 1 method call in case. just use removeone() and/or removeall() methods depending on exact scenario. therefore, writing this: qstringlist user_valid; user_valid << "marigold" << "cloud" << "sun" << "rain"; user_valid.removeone("marigold"); // user_valid: ["cloud", ,"sun", "rain"] if insist on using qvector<qstring>

php regex to alow slash in string -

here regex exclude special character other allowing few (-,%,:,@). want allow / getting issue return preg_replace('/[^a-za-z0-9_ %\[\]\.\(\)%:@&-]/s', '', $string); this works fine listed special character, but return preg_replace('/[^a-za-z0-9_ %\[\]\.\(\)%\\:&-]/s', '', $string); does not filter l chracter to. here link test: http://ideone.com/wxr0ka where not allow \\ in url. want dispaly url usual you're making mistake in entering http:// http:\\ regex needs include / in exclusion list. should work: function clean($string) { // replaces spaces hyphens. $string = str_replace(' ', '-', $string); // removes special chars. return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string); } $d = clean("this http://nice readlly n'ice 'test for@me to") ; echo $d; // this-was-http://nice-readlly-nice-test-for@me-to working demo

c# - File name is showing in wrong encode after uploading to ftp server -

after uploading of file ftp server, file name showing ????????. file name contains cyrillic words. inside of file showing correct. should done show correct file names? code here: fileinfo fileinfo = new fileinfo(filepath); string filename = fileinfo.name.tostring(); webrequest requestftp = webrequest.create(incomingftppath + filename); requestftp.credentials = new networkcredential(ftpusername, ftppassword); requestftp.method = webrequestmethods.ftp.uploadfile; filestream fstream = fileinfo.openread(); int bufferlength = 2048; byte[] buffer = new byte[bufferlength]; stream uploadstream = requestftp.getrequeststream(); int contentlength = fstream.read(buffer, 0, bufferlength); while (contentlength != 0) { uploadstream.write(buffer, 0, contentlength); contentlength = fstream.read(buffer, 0, bufferlength); } uploadstream.close(); fstream.

php - how to change local language from view in laravel? -

so worked in multi language project in laravel, create files in lang folder , when change language change successfully, when tried change view doesn't work, code change local language : <li><a onclick="{{app::setlocale('fr');}};location.reload(true);">francais</a></li> <li><a onclick="{{app::setlocale('en');}};location.reload(true);">english</a></li> app::setlocale('en'); isn't generate js code change language, set language current application, renders view.

Fail2Ban regex does not match -

i'm using fail2ban. reason fail2ban refuse compile regex. here logs need match: root@server1:/etc/fail2ban/filter.d# tail /var/log/apache2/error.log [sun apr 20 10:40:05 2014] [error] [client 75.144.181.151] user root: authentication failure "/phpmyadmin/": password mismatch [sun apr 20 10:40:16 2014] [error] [client 75.144.181.151] user root: authentication failure "/phpmyadmin/": password mismatch [sun apr 20 10:40:38 2014] [error] [client 75.144.181.151] user haker not found: /phpmyadmin/ [sun apr 20 10:40:44 2014] [error] [client 75.144.181.151] user pentest not found: /phpmyadmin/ and here fail2ban filter.d file: root@server1:/etc/fail2ban/filter.d# cat /etc/fail2ban/filter.d/phpmyadmin.conf [definition] failregex = [client <host>;] user .*; not found: \/phpmyadmin\/|[client <host>;] user root: authentication failure "\/phpmyadmin\/": ignoreregex = here regex line file above: [client <host>;] user .*; not found: \/

python - Draw network and grouped vertices of the same community or partition -

Image
i need view (drawn or plot) communities structure in networks i have this: import igraph random import randint def _plot(g, membership=none): layout = g.layout("kk") visual_style = {} visual_style["edge_color"] = "gray" visual_style["vertex_size"] = 30 visual_style["layout"] = layout visual_style["bbox"] = (1024, 768) visual_style["margin"] = 40 vertex in g.vs(): vertex["label"] = vertex.index if membership not none: colors = [] in range(0, max(membership)+1): colors.append('%06x' % randint(0, 0xffffff)) vertex in g.vs(): vertex["color"] = str('#') + colors[membership[vertex.index]] visual_style["vertex_color"] = g.vs["color"] igraph.plot(g, **visual_style) if __name__ == "__main__": karate = igraph.nexus.get("karate") cl

ios - What does it mean when a view is not in the window hierarchy? -

okay, i've tried implement delegate method on uiimagepickercontroller stated @michaelking in previous post of mine. - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { [picker dismissviewcontrolleranimated:false completion:nil]; image = [info objectforkey:@"uiimagepickercontrolleroriginalimage"]; } however, following error in code: warning: attempt present <uiimagepickercontroller: 0xc464f10> on <rpflipsideviewcontroller: 0xc66a270> view not in window hierarchy! i don't understand means, , searching online, haven't found i've been able understand. can please clarify? maybe still don't understand whole delegate thing? here previous post, reference: how reference picture took in ios? the view controller's view must on screen (not visible) must in hierarchy somewhere. without being in current view hierarchy there no graphics context in present picker.

stack - Java balanced expressions check {[()]} -

Image
i trying create program takes string argument constructor. need method checks whether string balanced parenthesized expression. needs handle ( { [ ] } ) each open needs balance corresponding closing bracket. example user input [({})] balanced , }{ unbalanced. doesn't need handle letters or numbers. need use stack this. i given pseudocode can not figure how implement in java. advice awesome. update- sorry forgot post had far. messed because @ first trying use char , tried array.. im not sure go. import java.util.*; public class expression { scanner in = new scanner(system.in); stack<integer> stack = new stack<integer>(); public boolean check() { system.out.println("please enter expression."); string newexp = in.next(); string[] exp = new string[newexp]; (int = 0; < size; i++) { char ch = exp.charat(i); if (ch == '(' || ch == '[' || ch == '{') stack.push(i); else if

c# - Semantic differences between FirstOrDefault() and Where() in sqlite-net -

more clarity question actual question have found solution. don't understand reasoning... using sqllite 3.8.3.1 using sqlite-net 2.1 i see distinct difference between running .where(lambda).firstordefault() running .firstordefault(lambda) . as far experience linq goes, database linq providers treat both of these same ( .firstordefault(lambda) may little faster if it's optimized properly, , large, these 2 calls take same time run). however, in sqlite-net, seeing following results on table ~40,000 records in it: when running .firstordefault(x => x.id == id) , seeing time taking on core-i7 between 2200ms 3700ms . on surface rt (1st gen) takes around 20,000ms-30,000ms.. when running .where(x => x.id == id).firstordefault() , seeing time taking on same core-i7 between 16ms-20ms . on surface rt, takes around 30ms. my question whether bug, or if that's conscious design decision. if it's design decision - love understand reasoning behind it. .w

java - Passing parameters through AsyncTask - android -

i'm trying pass integer through asynctask use in doinbackground on click of button. here passing parameters public void go(view view) { edittext input = (edittext)findviewbyid(r.id.txtinput); int downloads = integer.parseint(input.tostring()); processtask mytask = new processtask(); //5000 - number of ms simulate download mytask.execute(5000, downloads); } and here try use same values pass private class processtask extends asynctask<integer, integer, void>{ @override protected void doinbackground(integer... params) { // todo auto-generated method stub integer myd = params[1]; for(int = 0; i<myd; i++){ try{ thread.sleep(params[0]); publishprogress(i+1); }catch (interruptedexception e){ e.printstacktrace(); } } return null; } i keep getting following errors: 04-20 19:10:43.198: e/androidruntime(4363): fatal exception: main 04-20 19:10:43.198:

java - How to use APK source code in eclipse. (Modifyin and editing) -

i want analyze apk source code in eclipse project. using apktojava program eclipse project. when import project android project, has errors in classes. of problems show because of missing .class files. how can .class files. want see eclipse project without error. source code of apk, what?

mockito - Robolectric Retrofit test to Android test framework -

i trying write test in android testing framework run on emulator since can't use robolectric in project compatibility reasons. how switch , use ( activityinstrumentationtestcase2, activitytestcase )? maybe example? i trying convert test project , , here code package com.swanson.octodroid.test; import java.util.arraylist; import java.util.list; import org.junit.before; import org.junit.test; import org.junit.runner.runwith; import org.mockito.argumentcaptor; import org.mockito.captor; import org.mockito.mock; import org.mockito.mockito; import org.mockito.mockitoannotations; import org.robolectric.robolectric; import org.robolectric.shadows.shadowtoast; import org.robolectric.util.activitycontroller; import retrofit.callback; import com.swanson.octodroid.github; import com.swanson.octodroid.mainactivity; import com.swanson.octodroid.owner; import com.swanson.octodroid.repository; import static org.fest.assertions.api.assertions.assertthat; import static org.fest.as

database - MySQL Community Server Limitations -

could please tell limitations mysql community server & pros of mysql enterprise server? the following our daily transactional activity db atleast 10 million records created , updated on person day basis. scheduled procedures acting on records in addition application accessing them. i concerned db capacity (db size threshold,etc) , if withstand huge volume of data when opt mysql community server. thanks in advance. difference between mysql ce , mysql enterprise edition? difference between community edition , enterprise edition added support , tools. server same, enterprise edition gets updated more , stable quick bug fix support. safe , not make problem if decide move on oracle in future. mysql enterprise subscriptions include: mysql enterprise server reliable, secure , up-to-date version of world’s popular open source database the mysql enterprise monitor provides monitoring , automated ad visors eliminate security vulnerabilities, improve re

java - ListView doesn't work in my controller class Android -

i have problem app. have implemented mvc design pattern view , controller. controller have onclicklistener methods (4 buttons , listview). problem when activities begins buttons listeners responds listview stationnaire, can't click on , cant't scroll throught list. show code. hope please. all_products.xml <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/mylayout"> <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="389dp" android:layout_alignparentleft="true" android:layout_alignparenttop="true"> </listview> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap

php - Find total with only the first iteration from relationship -

in scenario have ticket model , ticketreply model. i can grab replies ticket $ticket->replies . considering status 1 or 3 of ticket or reply means state open/unresolved, how find total of tickets open eloquent way. $tickets = ticket::all(); $tickets_open = 0; foreach($tickets $t) { $tickets_open++; if(($t->replies()->first()->status == 2) || ($t->status == 2)) { $tickets_open--; } } return $tickets_open; is there more efficient way of doing eloquent ? since query run each iteration. if there not, can convert $tickets array , iterate it. update: $t->replies()->first()->status causing 1+n or without eager loading. i changed $t->replies->first()->status , 1+n gone. rookie mistake believe. you can use eager loading reduce number of queries. $tickets = ticket::with('replies')->get(); doing this, instead of running 1+n queries, end running 2 sql queries: select * tickets se

corona - Error when trying to add a point to my score counter. Lua -

i have error have run when trying create score counter lua game. here code have. score = 0 local playerscore = display.newtext("score" ..score, 0, 10, "americantypewriter-bold", 16); playerscore:settextcolor(0, 0, 0); playerscore.text = "score: " .. score function ball:touch( event ) if event.phase == "began" playerscore.text = playerscore.text + 1 ball:applyforce(0, -10) return true end end here line gives me error. playerscore.text = playerscore.text + 1 the error gives me. attempt perform arithmetic on field 'text' (a string value) you attempting add 1 string "score: 1" (where 1 may number), instead should increment score variable , update text. this should job. score = score + 1 playerscore.text = "score: " .. score

how do I make the http and https optional using in RegEx -

ok. should softball fix not programmer , bit under gun can't research , test. have following expression works great: https?:\/\/([1-9]\d{0,3})\.website\.com\/.*type=abc.adv=abc1234 i have come find out our backend system strip off http:// of url this http://123.website.com/?&guid=blahblahblah&page=something&type=abc&adv=abc1234&site= {siteid} think regex fails in these situations. may wrong. can confirm or maybe provide way make "http(s)://" optional? thx! just group , make optional group. (https?:\/\/)?([1-9]\d{0,3})\.website\.com\/.*type=abc.adv=abc1234

How to add elements from string added from console to a list in java -

Image
how can add elements list input in java. like if put: scanner reader = new scanner("a,b,c,d,e); i want have string[] = {a,b,c,d,e]; using scanner methods whiles , little bit lost sorry english( not main language) java string list while-loop java.util.scanner share | improve question edited apr 22 '14 @ 2:47 charles 42.7k 11 80 118 asked apr 22 '14 @ 0:45 alejandro 8 5   

php - Laravel login system -

Image
i'm doing app using laravel, , i'm doing login system. in login don't have problem, in logout browser gets error whoops, looks went wrong. my login function public function postsignin() { if (auth::attempt(array('email'=>input::get('email'), 'password'=>input::get('password')))) { return redirect::to('users/dashboard')->with('message', 'you logged in!'); } else { return redirect::to('users/login') ->with('message', 'your username/password combination incorrect') ->withinput(); } } my logout function public function getlogout() { auth::logout(); return redirect::to('users/login')->with('message', 'your logged out!'); } if remove line auth::logout(); page redirected can't use auth::check() verify if user logged in. after having error whoops, looks went wrong. if refresh pa

Animation Issue when Reusing code Android -

i have application spawn new enemy every 4 seconds. enemy goes right left using an translateanimation . animation takes 7 seconds total. the problem i'm facing when animation running, every time spawn new enemy, animation stops old 1 , starts animating new enemy. is there way animate 2 different objects using same translateanimation? just in case, here animation translate= new translateanimation( animation.absolute, (float) 1.0, animation.absolute, (float) -4.0, animation.absolute,0, animation.absolute,0); translate.setduration(10000); translate.setfillafter(true); //newiv enemy's imageview newiv.startanimation(translate); you can apply animation this make animation xml in anim folder <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareinterpolator="false">

java - CXF Logging request & response with content filtering or masking soap fields -

i log incoming requests & responses particular endpoint, content filtering. i.e. when have request that: <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"> <soap:body> <m:processphoto xmlns:m="http://www.w3schools.com/photos"> <m:name>apples</m:name> <m:description>photo apples in it</m:description> <!-- large encoded binary below --> <m:photo>anvzdcbhihjhbmrvbsb0zxh0dqpqdxn0igegcmfuzg9tihrlehqncmp1c3qgysbyyw5kb20gdgv4da0kanvzdcbhihjhbmrvbsb0zxh0dqpqdxn0igegcmfuzg9tihrlehqncmp1c3qgysbyyw5kb20gdgv4da0kanvzdcbhihjhbmrvbsb0zxh0dqp3b3csigkgzglkbid0ihrob3vnahqgdghhdcbhbnlvbmugd291bgqgymugaw50zxjlc3rlzcbpbibkzwnvzgluzyb0aglzlibjb25ncmf0cye=</m:photo> </m:processphoto> </soap:body> </soap:envelope> i filter it, looks in logs that <soap:envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"> <soap:body> <m:proces