Skip to content

Instantly share code, notes, and snippets.

View jasocox's full-sized avatar
💭
Probably coding

Jason Cox jasocox

💭
Probably coding
View GitHub Profile
@jasocox
jasocox / promises
Created July 9, 2019 20:42
Resolving a promise chain (promise.js "all" is broken)
#!/usr/bin/env node
console.log("Promise test");
var p1, p2, p3, p4;
var r1, r2, r3, r4;
p1 = new Promise(res => r1 = res);
p2 = new Promise(res => r2 = res);
p3 = new Promise(res => r3 = res);
#!/usr/bin/env node
const { Readable } = require("stream");
const { createReadStream, createWriteStream } = require("fs");
const readline = require("readline");
const DATA_MAX = 10000;
const DURATION_MAX = 10000;
function genDataStreamInner(dataMax, count, output) {
@jasocox
jasocox / downloadToNeo.js
Created February 15, 2019 20:32
Convert downloaded example data into JSON and then upload to Neo4j
#!/usr/bin/env node
const http = require('http');
var neo4j = require('neo4j-driver').v1;
var prettyjson = require('prettyjson');
var driver = neo4j.driver('bolt://54.162.113.152', neo4j.auth.basic('neo4j', 'password'));
var session = driver.session();
function processUserData(data) {
@jasocox
jasocox / generateCypherCreate.js
Last active February 15, 2019 18:51
Convert JSON into Cypher CREATE call
exports.generateCypherCreate = function(dataLabel, data) {
console.log("Data Label:", dataLabel);
var keys = Object.keys(data);
console.log("Keys:", keys);
var create = "CREATE (n: " + dataLabel " {";
create += keys.map( key => key + ": " + data[key]).join(", ");
create += "}) RETURN n";
};
@jasocox
jasocox / JSMapExample
Created November 15, 2017 21:48
An example of mapping over data in JavaScript.
var list = [1, 2, 3, 4];
var doubled = list.map(item => item * 2);
console.log(list);
console.log(doubled);
@jasocox
jasocox / gist:7376224
Created November 8, 2013 19:26
Stemming with elastic search. I'm adding an index with "Halls" in the name, and would like it to show up when searching for "hall"
# 2013-11-08 14:00:26:707 [CREATE] ("test_listings")
#
curl -X POST http://localhost:9201/test_listings -d '{"mappings":{"listing":{"properties":{"slug":{"type":"string"},"name":{"analyzer":"snowball","type":"string"},"description":{"type":"string"},"space_type_name":{"as":{},"type":"string"},"usages":{"as":{},"type":"string"},"amenities":{"as":{},"type":"string"},"nearbies":{"as":{},"type":"string"},"tags":{"as":{},"type":"string"},"camera_ok":{"type":"string"},"charitable":{"type":"string"},"accessible":{"type":"string"},"active":{"type":"string"},"demoable":{"as":"activatable?","type":"string"},"location_id":{"type":"string"},"location_slug":{"as":"location_slug","type":"string"},"location_name":{"as":"location_name","type":"string"},"location_lat_lon":{"as":"location_lat_lon","type":"geo_point"},"location_address":{"as":"location_address","index":"not_analyzed","type":"string"},"location_profile_image_url":{"as":"location_profile_image_url","index":"not_analyzed","type":"string"},"usages_for_facet":{"as":
@jasocox
jasocox / gist:5952324
Created July 8, 2013 20:43
Setting up the payout account
def setup_marketplace
api_key = Balanced::ApiKey.new.save
Balanced.configure api_key.secret
@marketplace = Balanced::Marketplace.new.save
# Add money to the account, so that it is useful...
card = @marketplace.create_card(
:card_number => "5105105105105100",
:expiration_month => "12",
@jasocox
jasocox / gist:5952091
Created July 8, 2013 20:12
bank code instead of routing number?
#<Balanced::Credit:0x007fa6d9c68180
@attributes=
{"amount"=>999,
"bank_account"=>
{"credits_uri"=>"/v1/bank_accounts/BA6yUq1nvNWoe6qhmOEnzBSC/credits",
"bank_name"=>nil,
"_type"=>"bank_account",
"bank_code"=>"9900000000",
"account"=>
#<Balanced::Account:0x007fa6d9f11490
ails s 5000 ~/Code/nozomi
WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.
To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
Exiting
/usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler.rb:63:in `require': cannot load such file -- rack/handler/5000 (LoadError)
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler.rb:63:in `try_require'
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/handler.rb:16:in `get'
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/server.rb:269:in `server'
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands/server.rb:59:in `start'
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/r
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/Users/jasocox/.rvm/bin:/Users/jasocox/src/android-sdk-mac_x86/tools:/Users/jasocox/src/android-sdk-mac_x86/platform-tools:/Users/jasocox/.rvm/bin:/usr/local/Cellar/ruby/1.9.3-p125/bin