Posts

ruby - re-try logic in a simple loop -

i'm trying set bounds array later printed in console , summed. lower bound ($a) should less 50 , wrote code evaluate that, want re-prompt number if higher number typed. far, google , experimentation have failed me. def num_a print "pick number 1 50: " $a = integer(gets.chomp) until $a < 50 puts "um, try again please." # need here prompt response # until $a less 50 end end you restructure loop prompt , call gets both inside it: def num_a # start number doesn't meet condition = 50 # check if number meets condition yet until < 50 # ask user enter number print "pick number 1 50: " = integer(gets.chomp) # ask try again if number isn't under 50 puts "um, try again please." unless < 50 end # return entered value caller end also, i've shown in example, recommend avoiding use of global variables ( $a in case).

ruby - Accessing variable name -

i trying parameter validation outside of rails. def create_statement(action, ...) valid_one_of(action, ['add', 'move', 'delete']) ... end validation method: def valid_one_of(input, valid_values) return true if valid_values.include?(input) raise "#{input} not valid value #{input.var_name}" end sample call: create_statement('bob') so output be: bob not valid value action the problem how input.var_name ? i workaround pass valid_one_of(action, ['add', 'move', 'delete'], 'action') (and use 3rd parm output) doesn't seem feels bit redundant. if not possible access variable name there more dry coding style workaround? i don't know of way name of local variable, , if could, name want? name of parameter define on method definition? name of variable in caller? i don't think "work-around" horrible, suggest couple of slight variations might read littl...

cytoscape.js - Setting control points for Cytoscape edges? -

Image
i'm trying build descending graph in cytoscape. i've got majority done quite well, i'm stuck on edge types. i'd use 'segments' curve-style, edges have points. however, instead of being zig-zags, edges constrained horizontal/vertical lines. my graph pretty constrained , user cannot manipulate positions. edges start @ 'parent' element, go straight down set amount, hit point, turn, head horizontally same x child, straight down child element. right now, lines go straight, , can add segments easily, aren't constrained , based on percentages won't have access without doing bunch of math, guess isn't terrible. current: desired: if want specific absolute positions on segments edges, you'll need convert absolute co-ordinates relative co-ordinates specify segments edges. if want different type of edges usecase, feel free propose in issue tracker.

c# - Error in creating twitterizer app in asp.net -

i using twitterizer dll post twit on twitter via oauth method give me error. "whoa there! there no request token page. that's special key need applications asking use twitter account. please go site or application sent here , try again; mistake." and code is: using system; using twitterizer; public partial class home : system.web.ui.page { protected void page_load(object sender, eventargs e) { var oauth_consumer_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; var oauth_consumer_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; if (request["oauth_token"] == null) { oauthtokenresponse reqtoken = oauthutility.getrequesttoken(oauth_consumer_key, oauth_consumer_secret, request.url.absoluteuri); response.redirect(string.format("http://twitter.com/oauth/authorize?oauth_token+{0}", reqtoken.token)); } else { string requesttoken = request["oauth_token"]....

Parse Text in Python (Django) -

i have text looks like: link(base_url=u'http://www.bing.com/search?q=site%3asomesite.com', url='http://www.somesite.com/prof.php?pid=478', text='somesite - professor rating of louis scerbo', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pid=478'), ('h', 'id=serp,5105.1')])link(base_url=u'http://www.bing.com/search?q=site%3asomesite.com', url='http://www.somesite.com/prof.php?pid=527', text='somesite - professor rating of jahan \xe2\x80\xa6', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pid=527'), ('h', 'id=serp,5118.1')])link(base_url=u'http://www.bing.com/search?q=site%3asomesite.com', url='http://www.somesite.com/prof.php?pid=645', text='somesite - professor rating of david kutzik', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pid=645'), ('h', 'id=se...

php - Intergrating Paypal into my shopping cart -

i have developed own shopping cart , want integrate paypal once user click checkout button. i need pass item details on paypal based on customer has added cart. believe code below checkout button nothing when clicked on. tried reason form doesn't see checkout button! <?php $checkout = "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>"; $checkout .= "<input type='hidden' name='cmd' value='_cart'><input type='hidden' name='upload' value='1'>"; $checkout .= "<input type='hidden' name='business' value='craig@biosboss.com'>"; $count = 1; $checkout .= "<input type='hidden' name='item_name_" + $count + "' value='" + $item['name']+ "'>"; $checkout .= "<input type='hidden' name='item_number_" + $count + "' value='...

excel - Copy & Paste range as values into next empty column on another sheet -

using command button, trying copy range (which varies based on inputs) values sheet. have code mentioned below, seems copying on top of last entry rather pasting next empty column. i'm new vba step step appreciated. thank you sub commandbutton3_click() dim source worksheet dim destination worksheet dim emptycolumn long set source = sheets("month template") set destination = sheets("sheet1") 'find empty column (actually cell in row 1)' emptycolumn = destination.cells(1, destination.columns.count).end(xltoleft).column if emptycolumn > 1 emptycolumn = emptycolumn + 1 end if source.range("m26:m35").copy destination.cells(1, emptycolumn) end sub try below sub commandbutton3_click() dim source worksheet dim destination worksheet dim emptycolumn long set source = sheets("month template") set destination = sheets("sheet1") 'find emp...

ios - Why set scrollview's delegate to nil in dealloc method? -

i found when slide tableview pressed button, project crashed , message :message sent deallocated instance. add - (void)dealloc { [self.tableview setdelegate:nil]; } project , crash doesn't happen again. still can't understand why project crash if didn't add code mentioned above. delegate deallocated , still sent message it? teach me this. following code in scrollview did scroll method. - (void)scrollviewdidscroll:(uiscrollview *)scrollview{ cgfloat y = scrollview.contentoffset.y; [self.navigationcontroller.navigationbar lt_setbackgroundcolor:gwprgbcolor(255, 255, 255, ((y-100)/100.0f))]; }

sql - Using Column Values from One Table within a Where Clause -

i have oracle table called: col_mapping column in table has column values of columns table. example data of table: col_mapping id descr col_vals ------------------------------ 1 label col_1 2 name_addr col_2:col_3 3 salary col4 based on above table, go through each record in col_mapping , use col_vals part of condition in table called other_tab , i.e.: select 'y' other_tab col_1 = 'whatever1'; select 'y' other_tab (col_2 = 'whatever2' or col_3 = 'whatever2'); , finally: select 'y' other_tab col_4 = 'whatever4'; i split out col_vals condition , there more 1 value colon separated, turn or condition above examples. any on how achieve above in oracle great. thanks. this not tested. how believe can accomplished. need 2 loops. 1 loop through table col_mapping , other loop through column col_vals each row , construct condition. something this: declare a_wh...

javascript - Saving the lastest state of an entire application in JS -

i have interactive web based visualization. want allow users able undo while interacting visualization. noticed people suggest writing own undo function in case might difficult (so many different things keep track of). how can save last state of entire application after each interaction? idea? thanks, you use more state-driven approach , use react + redux, sounds have existing app don't want recreate. in case, depends on data looks like. single json object? in case, clone object on , on "save" previous states. you implement database , save copy of needed data timestamps and/or version numbers allow roll back. lead lot of duplication of data. another approach keep track of events modify data, , opposite of event. basic example, add number 15 "total". if wanted undo that, subtract 15. however, works if performing operations on of data. if want apply different types of data, store event along previous value. example: change name "bob...

javascript - Responsiveslides just not working -

i'm using responsive slides , have gone according instructions on site http://responsiveslides.com/ shows first image , not slide...i have checked can see somehow doesn't work...i have uploaded on jsfiddle https://jsfiddle.net/q421n8xo/ , hope give me valuable advice :) thanks! oh , think dropdown menu blocked images, there way put in front? again! okay major(?) breakthrough: found out responsiveslides file downloaded incorrect...i got working on jsfiddle...kinda weird on computer. try further. <!doctype html> <html> <head> <title>hire bach</title> <link rel="stylesheet" type="text/css" href="css/main.css"> <script src="js/responsiveslides.min.js"></script> <script src="js/jquery-1.12.4.min.js"></script> <script> $(function() { $(".rslides").responsiveslides({ auto: false, ...

objective c - Purge x objects from Realm -

i want purge event log removing oldest event objects there doesn't seem straight forward way this. can fetch object sorted according how want them deleted, there no way limit - ie want first 100 in rlmresults. rlmresults <event *> *events = [[event allobjects] sortedresultsusingproperty:@"id" ascending:yes]; if loop through , delete them index events updated go won't work. rlmrealm *realm = [rlmrealm defaultrealm]; [realm beginwritetransaction]; (nsinteger = 0; < numbertopurge; i++) { [realm deleteobject:events[i]]; } [realm commitwritetransaction]; i can put add them seperate array , use delete, way works seems bit clunky, there better way? nsmutablearray *purgeevents = [[nsmutablearray alloc] initwithcapacity:numbertopurge]; (nsinteger = 0; < numbertopurge; i++) { [purgeevents addobject:events[i]]; } rlmrealm *realm = [rlmrealm defaultrealm]; [realm beginwritetransaction]; [realm deleteobjects:events]; [realm commitwritetransact...

apache - Error using PHP PEAR XAMPP 7.0.2.1 Net_Nmap -

i'm trying pear net_nmap package here: https://pear.php.net/package/net_nmap/ i have nmap installed on windows 10 machine. found following code should job. there should configure before use pear? i'm getting 2 errors: warning: require_once(xml/parser.php): failed open stream: no such file or directory in c:\xampp\htdocs\net_nmap-master\net\nmap\parser.php on line 31 fatal error: require_once(): failed opening required 'xml/parser.php' (include_path='c:\xampp\php\pear') in c:\xampp\htdocs\net_nmap-master\net\nmap\parser.php on line 31 <?php // scan network retrieve hosts , services information. require_once 'net/nmap.php'; //define target , options $target = array('193.95.13.16','www.google.com'); $options = array('nmap_binary' => 'c:\program files (x86)\nmap'); try { $nmap = new net_nmap($options); $nmap_options = array( 'os_detection' => true, 'service...

unity3d - Unity android "freezes" with splash image -

i have added custom theme background image serve "splash" image make app nicer while unity player loading. that's theme definition have <?xml version="1.0" encoding="utf-8"?> <resources> <style name="theme.test" parent="@android:style/theme.light.notitlebar.fullscreen"> <item name="android:windowbackground">@drawable/launchimage</item> <item name="android:windowcontentoverlay">@null</item> <item name="android:windownotitle">true</item> <item name="android:backgrounddimenabled">false</item> </style> </resources> now, when refer theme in androidmanifest.xml like: <activity android:name="com.unity3d.player.unityplayeractivity" android:theme="@style/theme.test" ... ></activity> the game "freezes" – it's hard tell in fact, because displays splash ...

How do I make my live templates in Android Studio to generate code like getters and setters according to variables that have already existed? -

now have made 1 this: public $type$ get$property$() { return $property$; } public void set$property$($type$ $property$) { this.$property$ = $property$; } where: type:complete() property:suggestvariablename() property:capitalize(property) it can generate code this: public get() { return ; } public void set( ) { this. = ; } but not want. i want generate getters , setters according variables,and don't have input types , names of variable again. if want setter , getter fot variable can use default way of insertion. press alt + insert . choose getter , setter. shown dialogue box variable names. can select variable there. can select multiple variable. notice might have press fn press insert . not answer want work want.

postgresql - Asking Postgres to add a non-existent sequence value -

i have existing postgres table, example: create table profiles( profile_id serial primary key, num_feed integer, num_email integer, name text ); alter table profiles alter column profile_id set default nextval('profiles_profile_id_seq'::regclass); alter table profiles add constraint profiles_pkey primary key (profile_id); create index "pi.profile_id" on profiles using btree (profile_id); and existing data, can't change, can add new ones. insert profiles values (3, 2, 5, 'adam smith'), (26, 2, 1, 'fran morrow'), (30, 2, 2, 'john doe'), (32, 4, 1, 'jerry maguire'), (36, 1, 1, 'donald logue'); the problem when tried insert new data, postgres add minimum value (which good) on column "profile_id" failed/error when hits existent value, because value exists. error: duplicate key value violates unique constraint "profile_id" detail: key (profile_id)=(3) exists. is...

c# - Keep differences between two hashtables -

i making function compares 2 hashtables , want keep difference of these tables. if both contain 100 keys , 2 have been altered want new hashtable equal 2 differences. here have. lost on how (keep differences) private hashtable comparehashtables(hashtable ht1, hashtable ht2) { hashtable resultsofcompare = new hashtable(); foreach (dictionaryentry entry in ht1) { if (ht2.containskey(entry.key) && ht2.containsvalue(entry.value) == false) { //keep differences } } return resultsofcompare; } it seems want check both key , value equality. if both don't match it's considered difference. creates bit of problem because type of difference can't represented in hash table. consider following ht1: key = "bob" value = 42 ht2: key = "bob" value = 13 here key same value difference. store every difference resulting structure need able contain 2 different values same key. that...

python - "Horse" Math game -

for computer science class final, have been instructed make our own game in python. requirements: 1. needs use both “while loop” , “for x in y loop.” 2. needs use list either keep track of information or score 3. needs use function gameplay, tracking score, both. 4. display art either @ beginning, after, or in between turns. 5. can multi player or single player. 6. must carry complexity commensurate final project. anyways, decided make game similar horse in basketball. object of game find answer of math problem before time runs out. if don't, letter in horse. once letters of horse, game over. here have far: import random import time timeit import default_timer print("welcome jared's math horse game!") time.sleep(1) print("you have basic geometry , algebra problem,and brain teasers...") time.sleep(1) print("for each wrong, letter, , spell 'horse'. once letters, lose. round nearest integer!!!!!!!!...

ruby on rails - Running a cron job at different times for each job -

i building application in rails allows users post products sale set duration of time. each product has different 'end_time' in want run method sets updates product status 'dead'. i've been reading on wheneverize gem, far can tell use doing recurring task every minute, hour, day, etc... ideas on how go running cron job run @ each product's specific 'end_time'? for example along lines of: live_products = product.where('status = ?', 'live') live_products.each |product| at: product.end_time product.status = 'dead' product.save end end cronjob, every minute, checking need transaction dead. product.turn_dead.update_all status: :dead #product.rb scope :live, -> {where status: :live} scope :out_of_time, -> {where "end_time <= ?", time.now} scope :turn_dead, ->{ live.out_of_time }

mvvm - Set the Visibility of Data Grid in WPF -

in application have 3 data grids in single xaml file. based on user selection want show 1 grid , hide other grids. in view model class have boolean property each grid , based on selection setting true or false.but grids visible . <datagrid visibility="{binding path=isgridvisible}" > in view model setting isgridvisible value public bool iscapexgridvisible { { return iscapexgridvisible; } set { iscapexgridvisible = value; raisepropertychangedevent("iscapexgridvisible"); } } please provide ideas. thanks visibility property on uielement not boolean. enum 3 values: collapsed not display element, , not reserve space in layout. hidden not display element, reserve space element in layout. visible display element. so in order set viewmodel should: - make property type of visibility (not best solution in world) - use converter binding trick of translating boolean visibility public class booleantocolla...