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
// | |
// Simplified (and mostly incorrect) definition of the Maybe monad. | |
// | |
class Maybe { } | |
class Nothing extends Maybe { } | |
class Just extends Maybe { | |
constructor(v) { |
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 bash | |
CURL=$(which curl) | |
if [[ ! -x "${CURL}" ]]; then | |
echo "Missing dependency. Please install curl (https://formulae.brew.sh/formula/curl): | |
$ brew install curl" 1>&2 | |
exit 1 | |
fi | |
readonly PROGRAM=$(basename -- $0) |
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
const { asKey } = require('./utils'); | |
const text = { | |
"520407a476092ac19c671e1e75d052bd": "i18n!", | |
}; | |
const gettext = (str) => text[asKey(str)] || str | |
console.log(gettext("Iлtèrnåtïonɑlíƶatï߀ԉ")); //=> "i18n!" | |
console.log(gettext("Autre chose!")); //=> "Autre chose!" |
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 Model { | |
constructor() { | |
this.userCollection = [ ] | |
this.selectedUser = null | |
this.listeners = { | |
'selectedUser': [ ], | |
'userCollection': [ ] | |
} | |
} |
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
import javax.management.* | |
import javax.management.remote.* | |
var serverUrl = "service:jmx:rmi:///jndi/rmi://0.0.0.0:9090/jmxrmi" | |
var connection = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl)).getMBeanServerConnection() | |
var objectName = new ObjectName("my-domain:type=my-bean-type,name=my-bean-name") | |
var pingResult = (int) connection.invoke(objectName, "ping", null, null) // Assumes an `int ping()` method that returns the error code. | |
/exit pingResult |
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
import sys | |
import re | |
import subprocess | |
import os | |
# | |
# Usage: | |
# $ youtube-dl -f 140 https://www.youtube.com/watch?v=Iq0xfewozjw | |
# $ python3 split.py <input file name>.m4a tracks.txt | |
# |
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
// heavily inspired by https://github.com/JMPerez/promise-throttle | |
const throttle = (f, rate) => { | |
// rate is # of calls/sec | |
const period = 1/rate * 1000 // minimum elapsed time (in ms) between calls (sec/call * 1000ms/sec) | |
const queue = [ ] // queued function calls | |
let last = 0 // last time `f` was called | |
const applyNext = () => { | |
if (queue.length === 0) return |
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
import React from 'react' | |
import ReactDOM from 'react-dom' | |
import thunk from 'redux-thunk' | |
import logger from 'redux-logger' | |
import { Provider, connect } from 'react-redux' | |
import { createStore, applyMiddleware } from 'redux' | |
import Immutable from 'immutable' | |
import './index.css' | |
// |
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
const handleResolve = (breaker) => (value) => { | |
breaker.state = closed | |
breaker.errorCount = 0 | |
return Promise.resolve(value) | |
} | |
const handleReject = (breaker) => (reason) => { | |
breaker.errorCount += 1 | |
breaker.state = (breaker.errorCount >= breaker.maxErrorCount ? opened : closed) | |
if (breaker.state === opened) setTimeout(() => breaker.state = halfOpened, breaker.resetTimeout) |
NewerOlder