Skip to content

Instantly share code, notes, and snippets.

View thejsj's full-sized avatar

Jorge Silva thejsj

View GitHub Profile
@thejsj
thejsj / index.js
Created December 12, 2016 07:02
Javascript Cloning for Arrays
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
@thejsj
thejsj / if-else-case.js
Created November 21, 2016 06:00
Ejemplos Para Jaime
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;
@thejsj
thejsj / index.js
Created November 21, 2016 03:06
Return vs Else Example
'use strict'
// All these functions behave the same way
const getHello = function (a) {
if (a === true) {
return 'hello'
}
else {
return 'wow'
@thejsj
thejsj / fizzbuzz.hs
Last active August 31, 2016 04:50
FizzBuzz in Haskell
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
@thejsj
thejsj / token.js
Created August 25, 2016 20:44
Stripe Node Shortcuts
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)
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
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
@thejsj
thejsj / tableCreate.js
Created May 26, 2015 23:35
A simple script showing RethinkDB's JavaScript API
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)
@thejsj
thejsj / basic-reql-queries
Created May 19, 2015 23:03
Basic ReQL Queries
# Queries
## Setup
Create the database in the data explorer. If you're using a shared instance of RethinkDB, name space your database name with your GitHub handle. If you're running these queries locally, you don't need to name space your database name.
```
r.dbCreate('GITHUB_HANDLE_rethinkdb_workshop')
r.db('GITHUB_HANDLE_rethinkdb_workshop').tableCreate('reddit')
```
@thejsj
thejsj / if.js
Last active August 29, 2015 14:19
var obj = {
if: function (condition, trueStatement, falseStatement) {
if (condition) return trueStatement;
return falseStatment;
},
in: function () {
console.log('This is an `in` method');
},
arguments: function () {
console.log('This is an `arguments` method');