Posts

ruby - Excluding one list of items from another -

i have yml file looks this: level 1: seattle: name: "rick" id: "95155" time: "2:00 pm" car: "hyundai" denver: name: "arnold" id: "82594" time: "2:00 pm" car: "mitsubishi" level 2: san antonio: name: "james" id: "96231" time: "2:00 pm" car: "honda" minneapolis: name: "ron" id: "73122" time: "2:00 pm" car: "dodge i need read id values array processing, remove them array. ways go this? you can read id values array processing in below way : require 'yaml' yml = <<-_end_ --- level1: seattle: name: "rick" id: "95155" time: "2:00 pm" car: "hyundai" denver: name: "arnold" id: "82594" time: "2:00 pm" car: "mitsubishi" level 2: san antoni...

hash - Sorting two hashes into one in Python -

i have 2 hash fp['netc'] containing cells connected specific net example: 'net8': ['cell24', 'cell42'], 'net19': ['cell11', 'cell16', 'cell23', 'cell25', 'cell32', 'cell38'] and fp['celld_nm'] containing x1,x0 coordinate each cell example: {'cell4': {'y1': 2.164, 'y0': 1.492, 'x0': 2.296, 'x1': 2.576}, 'cell9': {'y1': 1.895, 'y0': 1.223, 'x0': 9.419, 'x1': 9.99} i need create new hash (or list) give x0 , x1 each cell in spesific net. instance: net8: cell24 {xo,x1} cell42 {xo,x1} net 18: cell11 {xo,x1} ... here code l1={} l0={} net in fp['netc']: cell in fp['netc'][net]: x1=fp['celld_nm'][cell]['x1'] x0=fp['celld_nm'][cell]['x0'] l1[net]=x1 l0[net]=x0 print l1 print l0 ...

Is it possible to change Java syntax within a project? -

is there way define custom syntax given java project? for example, 1 thing able create short-hand syntax standard getters , setters (similar .net's "{ get; set; }"). i've been searching, i've come across writing dsl might able accomplish this, looking them, don't know suit need. so there way define syntactical elements this? since others have established changing syntax not possible, might interested in project lombok . from getting started guide: private boolean employed = true; private string name; public boolean isemployed() { return employed; } public void setemployed(final boolean employed) { this.employed = employed; } protected void setname(final string name) { this.name = name; } becomes @getter @setter private boolean employed = true; @setter(accesslevel.protected) private string name;

c# - Possible to automatically add elements to collection? -

i new @ entity framework (and stack overflow - first question!): right got following entities in db: blog: [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int id { get; set; } public virtual ilist<post> posts { get; set; } post: [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int id { get; set; } public int blogid { get; set; } [required] [foreignkey("blogid")] public virtual blog blog { get; set; } currently whenever add post manually add collection of corresponding blog. wonder if it's possible automatically add them collection add posts referencing corresponding blog? you use entity class create entity rather new , ie: posts.add(post.create()); instead of posts.add(new blog()); but if must pass arguments, need do post p = post.create(); p.blogid = 1234; p.somestring = "test"; p.somedate = datetme.now; posts.add(p); and always, call db.savechanges();

sed output blank in bash script -

i have file consists of following hundred lines in addition other data (abc-wxyz1/2222 1234) 1234 random number different 100 lines. want substitute lines with (abc-wxyz1/2222 *) i using following code it cat input.txt | \ sed -i -e 's/\(abc\-wxyz1\/2222\ [0-9]\+\)/\(abc\-wxyz1\/2222\ \*\)/g' > output.txt i output.txt blank have no clue why. doing correctly ? if you're going use flag -i, --in place , don't have redirect output. substitutions performed in place , expected. yet, can simplify expression, doing: sed -i -e 's/abc\-wxyz1\/2222\ \([0-9]\+\)/*/g' input.txt

jquery - Determine user location then redirect to different home page -

i want able change image depending on location user has viewed site from? or alternatively navigate them page. ideally pick using jquery, i'm not 100% sure if effective. for example, want swap in different image if user visiting site london. can region specific? thanks gillian just got work of beda0805 here's solution <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>location</title> <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script> <script type='text/javascript'>//<![cdata[ $(window).load(function(){ $.get("http://ipinfo.io", function (response) { if(response.region == 'london'){ $("#address").append("<p>your in london</p>"); } if(response.region != 'london'){ $("#add...

sql - Select tuple member from a list with condition in python/pyodbc -

i have list this a =[ ( 1, 10, 3), (1, 2, 3), (1, 11, 3), (2, 6, 4), (2, 5, 4) ] i need make list like b = [ ( 1, 2, 3), (2, 5, 4) ] the condition if first , third values of member of equal member select member having smallest 2nd value. in example member of 5 , of 2 group having first , third members equal. in case numbers might high. not figure out how python 2.7. its helpful if query ok pyodbc considering each member of record , member of each tuple column. an alternate: from sys import maxint =[ ( 1, 10, 3), (1, 2, 3), (1, 11, 3), (2, 6, 4), (2, 5, 4) ] results = {} x, y, z in a: key = (x, z) results[key] = min(y, results.get(key, maxint)) results = [(x, y, z) (x, z), y in results.items()] print results