This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var r = require('rethinkdb'); | |
var assert = require('assert'); | |
// Sample table names | |
var sampleTableName1 = 'sample_table_' + Math.floor(Math.random() * 10000); | |
var sampleTableName2 = 'sample_table_' + Math.floor(Math.random() * 10000); | |
// Create a table using callbacks | |
r.connect(function (err, conn) { | |
r.db('test').tableCreate(sampleTableName1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List.Split | |
import Data.Char | |
import Data.Maybe | |
import Text.Read | |
converToFloat :: String -> Maybe Float | |
converToFloat x = readMaybe x :: Maybe Float | |
convertStringsToFloats :: [String] -> [Float] | |
convertStringsToFloats x = map fromJust $ filter (not . null) $ map converToFloat x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-get-by-id () { | |
curl -s https://api.github.com/user/$1 | python -m json.tool | |
} | |
github-get-by-username () { | |
curl -s https://api.github.com/users/$1 | python -m json.tool | |
} | |
github-get-by-orgname () { | |
curl -s https://api.github.com/orgs/$1 | python -m json.tool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('loadenv')() | |
const stripe = require('stripe')(process.env.STRIPE_API_KEY) | |
var token1, token2 | |
stripe.tokens.create({ card: { "number": '4242424242424242', "exp_month": 12, "exp_year": 2017, "cvc": '123' }}).then(x => token1 = x) | |
stripe.tokens.create({ card: { "number": '4242424242424242', "exp_month": 1, "exp_year": 2020, "cvc": '456' }}).then(x => token2 = x) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fizzbuzz :: Int -> String | |
fizzbuzz x | mod x 15 == 0 = "fizzbuzz" | |
| mod x 5 == 0 = "fizz" | |
| mod x 3 == 0 = "buzz" | |
| otherwise = show x | |
printAll [] = return () | |
printAll (x:xs) = putStrLn x >> printAll xs | |
main = do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// All these functions behave the same way | |
const getHello = function (a) { | |
if (a === true) { | |
return 'hello' | |
} | |
else { | |
return 'wow' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user = prompt("Where you at?").toUpperCase(); | |
var isSingle = prompt("Are you single?").match(/yes/); | |
var isHappy = prompt("Are you happy?").match(/yes/); | |
switch(user) { | |
case 'HOME': | |
console.log("it is nice to have a home"); | |
break; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1, 2, 3] | |
var b = a // b now points to the same array as a | |
a === b // true | |
var c = [...a] // Makes a shallow copy of the array | |
c === a // false | |
a.push(4) | |
b // [1, 2, 3, 4] | |
c // [1, 2, 3] | |
a = null | |
b // [1, 2, 3, 4] Still point to the same array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/a/22063440/2684055 | |
function allPermutations (arr) { | |
function permutate (res, value, key, arr) { | |
if (arr.length <= 1) return [value] | |
// Eliminate current value | |
let result = arr.slice(0, key).concat(arr.slice(key + 1)) | |
.reduce(permutate, []) | |
.map(perm => [value].concat(perm)) | |
return res.concat(result) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sieve (n) { | |
let all = [...Array(n).keys()].map(x => true) | |
for (let i = 2; i <= Math.sqrt(n); i += 1) { | |
if (all[i]) { | |
for (let j = i * i; j < n; j += i) { | |
all[j] = false | |
} | |
} | |
} | |
return all.map((x, i) => { |