Posts

bit manipulation - Manipulating Bit-wise Operations -

there puzzle question of creating equivalent bit-wise & | , ~ operators. i've been doing brute force combinations of | , ~ using 6 (0110) , 5 (0101) trying 4 (0100), still cannot answer. the maximum number of operation can used 8. can please give me hints? what helps here de morgan's law , says: ~(a & b) == ~a | ~b thus can negate , get: a & b == ~(~a | ~b) //4 operations and looking @ truth table (and in fact, god bless simplicity of binary logic, there 4 possible combintations of inputs generate appropriate outputs for) can see both equivalent (last 2 columns): a | b | ~a | ~b | ~a or ~b | ~(~a or ~b) | , b --|---|----|----|----------|-------------|-------- 0 | 0 | 1 | 1 | 1 | 0 | 0 1 | 0 | 0 | 1 | 1 | 0 | 0 0 | 1 | 1 | 0 | 1 | 0 | 0 1 | 1 | 0 | 0 | 0 | 1 | 1

javascript - I made a simple chat room with sockets.io, how do I prevent XSS attacks? -

as title says made simple chat room sockets.io, problem have no xss protection , buddies keep putting infinite loops usernames, can imagine how trolly getting :p. app.js /** * module dependencies. */ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path'); var app = express(); // environments app.set('port', process.env.port || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyparser()); app.use(express.methodoverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); // development if ('development' == app.get('env')) { app.use(express.errorhandler()); } app.get('/', routes.index); app.get('/users', user.list...

change python to ruby, very basic -

i not familiar ruby, , want change python code ruby art project, here broken ruby script, know "split" function same, , not sure how 1 part of array in ruby. feel appreciated if can me out right now. new = line.split(" ") lala = [w w in new if len(new)>=4] newone = lala[1..6].join(" ") + "\n" + lala[6...].join(" ") the initial python code new = line.split(" ") lala = [w w in new if len(new)>=4] newone = (" ").join(lala[1:6]) +"\n" +(" ").join(lala[6:]) words = line.split(" ") s = words.select {|w| words.length >=4} result = s[1...6].join(" ") + "\n" + s[6..-1].join(" ")

javascript - jquery.extend(true, [], obj) not creating a deep copy -

jsfiddle here . if deep copying worked, output "curious george" , not "ender's game". how can make deep copy? answer this question indicates $.extend(true, [], obj) creates deep copy. yet example shows doesn't. function person(){} person.prototype.favorite_books = []; var george = new person(); george.favorite_books = ["curious george"]; var kate = new person(); kate.favorite_books = ["the da vinci code", "harry potter"]; var people = [kate, george]; var people_copy = $.extend(true, [], people); people_copy[0].favorite_books[0] = "ender's game"; $('#text').text(people[0].favorite_books[0]); solution i updated jsfiddle. turns out need deep copy each object in array individually if object custom object (that is, $.isplainobject returns false). and here real answer: at moment jquery can clone plain javascript objects, while you're using custom ones. , that's obvious, si...

ruby on rails - Setting a child attribute from parent in FactoryGirl -

how set dependent attribute depends on in factorygirl? factorygirl.define factory :line_item quantity 1 price 30 # want price come product association: self.product.price cart order product end end i tried didn't work: factory :line_item |f| f.quantity 1 f.cart f.order f.product after_build |line_item| line_item.price = line_item.product.price end end try this: factorygirl.define factory :line_item quantity 1 price { product.price } cart order product end end

c# - NServiceBus message removed from queue w/o a trace -

Image
i created new nservicebus azure worker role. the configuration simply: nservicebus.configure.with(busassemblies) .log4net() .license(config.default.nservicebus_license) .defineendpointname(endpointname) .unitybuilder(servicebusdiconfiguration.container) .azureconfigurationsource() .azuresagapersister() .azuresubcriptionstorage() .azuredatabus() .jsonserializer() .azureservicebusmessagequeue() .unicastbus() .loadmessagehandlers() .createbus() .start() the client configuration identical above except addition call .donotautosubscribe() . client uses bus.send(message) input queue of listener. azure bus queue reported messages being sent input que...

javascript - Getting location data from an image (Instagram/JS) -

i've been working on side project , have hit roadblock. can search through tags , display picture results fine, i'd put details below each picture, location information. i'm doing in javascript, , commented out lines believe need adjusted, comment marks removed not pictures show up. tips? json object printed call instagram returns data: object - data: array[20] - 0: object + caption: object + comments: object created_time: "1334402906" filter: "nashville" id: "169306311223447303_5913362" - images: object + low_resolution: object - standard_resolution: object height: 612 url: "http://distilleryimage7.instagram.com/f3f8d7b2862411e19dc71231380fe523_7.jpg" width: 612 + thumbnail: object + likes: object link: "http://instagr.am/p/jzfzfqti8h/" location: object tags: array[1] ty...