Posts

Erlang understand recursion -

i have problems understanding recursion , hoping help. have 2 examples answers can't understand how outcomme calculated. f1(x, [x | ys]) -> [x] ++ f1(x, ys); f1(x, [y| xs]) -> tl(f1(y, xs)) ++ [x]; f1(x, []) -> [x,x]. if run code with: f1(2, [1,1,1,6]). -> [1,6,1,2] another example: f1(c, [f,b,d,d,a]) -> [b,f,c] can please explain me how function calculates? :) another recursion function can't grasp one: f2([x|xs]) when x > 2 -> [x|f2(xs)]; f2([x|xs]) -> [y|ys] = f2(xs), [y,x+y|ys]; f2([]) -> [1]. example: f2([3,1,2]). -> [3,1,2,3]. how that? thanks in advance :) these examples make use of erlang's pattern matching. the first clause of first example match if first element of list same first argument f1(x, [x | ys]) -> [x] ++ f1(x, ys); the second clause match other cases list not empty f1(x, [y| xs]) -> tl(f1(y, xs)) ++ [x]; and last clause matches empty list. f1(x, []) -> [x,x]. when ev...

android - getLastLocation does not work on second time -

i'm using google play services user's last known connection. @override public void onconnected(bundle connectionhint) { final location lastlocation = locationservices.fusedlocationapi.getlastlocation( _googleapiclient); } @override protected void onresume() { super.onresume(); connecttogoogleplay(); } @override protected void onpause() { super.onpause(); if (_googleapiclient != null) { _googleapiclient.disconnect(); } } works expected. the problem occurs whenever i'm clicking on button , starting application again. app crashes because getlastlocation return null. formal documentation states - if location not available, should happen rarely, null returned. fine, know sure location exists, retrieved second ago. i did quick experiment , removed _googleapiclient.disconnect(); , works, somehow disconnect erases last location why ? missing ? a few thin...

javascript - How to use angularjs to change the values of another select tag? -

i have 2 web api's calling. each value in first api type has id needs used filter second api category. json below: // types [{"id":1,"text":"hardware","description":"hardware"}, {"id":2,"text":"software,"description":"software"}"}]; // categories [{"id":1,"typeid":1,"parentid":0,"name":"printing"}, {"id":2,"typeid":1,"parentid":1,"name":"toner"}] first of all, have store selectedtypeid used filter array, , can call angular $filter in second array. sintax: $filter('filter')(array, expression, comparator) e.g: $filter('filter')($scope.categories, {typeid: $scope.selectedtypeid}, comparator)

cql - Column order when importing CSV into Cassandra with cqlsh -

i'm new cassandra. cql appears ignore column order in create table statement, , order columns primary key first , remaining columns in lexicographic order. understand that's how they're stored internally, coming traditional database perspective, disregarding column order , leaking implementation detail user surprising. documented anywhere? [cqlsh 4.1.1 | cassandra 2.1.8 | cql spec 3.1.1 | thrift protocol 19.39.0] cqlsh:test> create table test (c int primary key, b text, int); cqlsh:test> describe table test; create table test ( c int, int, b text, primary key (c) ) that makes difficult import csv file columns in order thought using. cqlsh:test> copy test stdin; [use \. on line end input] [copy] 1,abc,2 bad request: line 1:44 no viable alternative @ input ',' (... c, b) values ([abc],...) aborting import @ record #0 (line 1). previously-inserted values still present. 0 rows imported in 7.982 seconds. cqlsh:test> copy test stdin; [...

sql server - SET NOCOUNT ON using ADO is not supressing PRINT messages -

in application using following code: set ors = oconn.execute("set nocount on; execute mysp;") mysp returns print messages , application returning them errors. how make print messages don't show won't trigger error in application? i tried set set nocount on; doesn't seem fix it. set nocount on suppresses (n) row(s) affected message. to stop print statements executing inside procedure, need remove them print statements procedure definition.

c# - Authenticating Mandrill Inbound Webhook Requests in .NET -

i'm using mandrill inbound webhooks call method in wcf api. request coming through, can parse it, etc. my problem lies in getting value of x-mandrill-signature header match signature i'm generating (based on process detailed here: https://mandrill.zendesk.com/hc/en-us/articles/205583257-authenticating-webhook-requests ). this i'm doing: list<string> keys = httpcontext.current.request.params.allkeys.tolist(); keys.sort(); string url = "mymandrillwebhookurl"; string mandrillkey = "mymandrillwebhookkey" foreach (var key in keys) { url += key; url += httpcontext.current.request.params[key]; } byte[] bytekey = system.text.encoding.ascii.getbytes(mandrillkey); byte[] bytevalue = system.text.encoding.ascii.getbytes(url); hmacsha1 myhmacsha1 = new hmacsha1(bytekey); byte[] hashvalue = myhmacsha1.computehash(bytevalue); string generatedsignature = c...

linux - Installation problems with Mongo on Nitrous.io container -

i created ubuntu container on nitrous.io can develop on chromebook without chromebook's limitation. having trouble using mongodb. followed these steps install it: ~ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7f0ceb10 ~ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list ~ sudo apt-get update ~ sudo apt-get install -y mongodb-org ~ sudo service mongod start i can't connect mongo through mongo shell. error message: mongodb shell version: 3.0.6 connecting to: test 2015-10-02t21:13:56.629+0000 w network failed connect 127.0.0.1:27017, reason: errno:111 connection refused 2015-10-02t21:13:56.630+0000 e query error: couldn't connect server 127.0.0.1:27017 (127.0.0.1), connection attempt failed @ connect (src/mongo/shell/mongo.js:179:14) @ (connect):1:6 @ src/mongo/shell/mongo.js:179 exception: connect failed i hav...