This file contains 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
// Filter object array based on attributes | |
var foo = [{'a':1, 'b':2}, {'a':2}, {'a':1}] | |
foo.find(o => o.a === 1) // return { a: 1, b: 2 } |
This file contains 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
class Person(object): | |
number = 0 # <= define a static variable | |
def __init__(self, name): | |
self.name = name | |
def say_hello(self): | |
print("Hello, I'm {name}!".format(name = self.name)) | |
def say_number(self): |
This file contains 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
#!/usr/bin/env python | |
import yaml | |
from pyspark import SparkContext | |
from pyspark.sql import SQLContext | |
sc = SparkContext() | |
sqlContext = SQLContext(sc) | |
# create dataframe |
This file contains 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 bcrypt = require('bcrypt'); | |
const saltRounds = 10; | |
const myPlaintextPassword = 's0/\/\P4$$w0rD'; | |
const someOtherPlaintextPassword = 'not_bacon'; | |
// Hash a password | |
bcrypt.genSalt(saltRounds, function(err, salt) { | |
bcrypt.hash(myPlaintextPassword, salt, function(err, hash) { | |
console.log('> hash a password (generate a salt and hash on separate function calls)'); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Handmade Redux Demo</title> | |
</head> | |
<body> | |
<div> | |
Counter: | |
<span id="counter"></span> | |
</div> |
This file contains 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
#!/bin/bash | |
mkdir -p src/{main,test}/{java,resources,scala} | |
mkdir lib project target | |
# create an initial build.sbt file | |
echo 'name := "MyProject" | |
version := "1.0" | |
scalaVersion := "2.10.0"' > build.sbt |
This file contains 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
object HelloWorld { | |
case class Text(content: String) | |
case class Prefix(text: String) | |
// step 2: capture the String conversion in implicit function; | |
// then find an implicit parameter and end up with finding "prefixLOL" | |
implicit def String2Text(content: String)(implicit prefix: Prefix) = { | |
// step 3: return instance of Text | |
Text(prefix.text + " " + content) | |
} |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
''' | |
Calculate the singular value decomposition using the power method. | |
''' | |
import numpy as np | |
from numpy.linalg import norm | |
from random import normalvariate |
This file contains 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
#!/usr/bin/env python | |
import numpy as np | |
import sklearn.datasets | |
import matplotlib.pyplot as plt | |
def load_data(n_samples=100, noise=None): | |
np.random.seed(0) | |
return sklearn.datasets.make_moons(n_samples=n_samples, noise=noise) |
This file contains 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
#!/usr/bin/env python | |
import urllib2 | |
import numpy as np | |
from keras.models import Sequential | |
from keras.layers import Dense | |
from keras.wrappers.scikit_learn import KerasRegressor | |
from sklearn.model_selection import cross_val_score | |
from sklearn.model_selection import KFold | |
from sklearn.preprocessing import StandardScaler |
NewerOlder