Skip to content

Instantly share code, notes, and snippets.

// quicksort sorting algorithm, in 2 lines of code
let quicksort = ([a, ...as]) => {
if (a == null) return as
return quicksort(as.filter(x => x <= a))
.concat([a])
.concat(quicksort(as.filter(x => x > a)))
}
let test1 = [5,1,2,3,5,6];
abstract class AngularShim extends React.Component<Props, State> {
private _div
public state = {
scope: null
}
componentWillMount() {
const scope = Object.assign($rootScope.$new(true), { props: this.props }, this.getScopeMethods())
this.setState({scope})
}
// Drag n Drop, using streaming paradigm
const fromEvent = Rx.Observable.fromEvent
const widget = document.getElementById('widget')
const container = document.getElementById('container')
// streams
const mouseDowns = fromEvent(widget, 'mousedown')
const mouseUps = fromEvent(container, 'mouseup')
const mouseMoves = fromEvent(container, 'mousemove')

merge

[s1] ----a-----b--c---->
[s2] o----------------->
   s3 = s1.merge(s2)
[s3] o---a-----b--c---->

startsWith, merge

// Place your settings in this file to overwrite the default settings
{
"filePicker.alternateFileNameMatching": true,
"editor.fontLigatures": true,
"editor.fontFamily": "Fira Code",
"editor.fontSize": 15,
"editor.lineHeight": 22,
"editor.tabSize": 2,
"editor.wrappingColumn": -1,
"editor.formatOnType": true,
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "shift+cmd+-", "command": "workbench.action.openPreviousEditor" },
{ "key": "shift+cmd+=", "command": "workbench.action.openPreviousEditor" },
{ "key": "shift+cmd+-", "command": "workbench.action.quickOpenNavigatePrevious",
"when": "inQuickOpen" },
{ "key": "shift+cmd+=", "command": "workbench.action.quickOpenNavigateNext",
"when": "inQuickOpen" },
{ "key": "shift+cmd+[", "command": "editor.foldLevel2",
"when": "editorFocus" },
class Peribot
constructor: (robot) ->
@cache = null
@robot = robot
@robot.brain.on 'loaded', => # ... set up @cache
@listen() # sets up robot listeners
add: (user_or_hashtag) -> # ...
remove: (user_or_hashtag) -> # ...
sniffer = require('twitter-sniffer')({ # TODO: implement module
consumer_key: '...', # TODO: add key
consumer_secret: '...', # TODO: add key
access_token: '...', # TODO: add key
access_token_secret: '...' # TODO: add key
})
SNIFF_PHRASE = "Live on #Periscope"
class Rational(x: Int, y: Int) {
// private method
private def gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)
// private value
private val g = gcd(x, y)
// accessor methods
def numer = x / g // normalize using gcd
@albertywu
albertywu / tree.js
Last active January 19, 2017 02:33
class Tree {
constructor(value, children = []) {
this.value = value
this.children = children
}
isLeaf() {