Skip to content

Instantly share code, notes, and snippets.

View why-jay's full-sized avatar

YJ Yang why-jay

View GitHub Profile
@why-jay
why-jay / test.md
Last active August 29, 2015 14:27
test.md
index c mu
1 2 3
@why-jay
why-jay / Error message
Created June 26, 2015 04:06
Why does foo-test fail?
Using Jest CLI v0.4.13
FAIL __tests__/foo-test.js (0.896s)
● foo() › it should throw
- Expected function to throw an exception.
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
int main() {
vector<thread> workers;
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
int main()
{
vector<thread> workers;
for (int i = 0; i < 5; ++i)
List<Runnable> actions = new ArrayList<Runnable>();
for (int counter = 0; counter < 10; counter++) {
final int copy = counter; // notice the `final` keyword!
actions.add(new Runnable() {
public void run() { System.out.println(copy); }
});
}
List<Runnable> actions = new ArrayList<Runnable>();
for (int counter = 0; counter < 10; counter++)
{
final int copy = counter; // notice the `final` keyword!
actions.add(() -> { System.out.println(copy); });
}
List<Action> actions = new List<Action>();
for (int counter = 0; counter < 10; counter++)
{
int copy = counter; // block-scoping in action!!
actions.Add(() => Console.WriteLine(copy));
}
// immutable version
const map = arr =>
arr.reduce((prev, cur) => prev.concat(cur), []);
// mutable version
const map = arr =>
arr.reduce((prev, cur) => {
prev.push(cur);
return prev;
}, []);
const Bluebird = require('bluebird');
const fs = Bluebird.promisifyAll(require('fs'));
const getFilenamesContainingMichaelAsync = Bluebird.coroutine(function* (path) {
const filenames = yield fs.readdirAsync(path);
return filenames.filter(name => name.indexOf('Michael') !== -1);
});
Bluebird.coroutine(function* () {
const filenamesContainingMichael = yield getFilenamesContainingMichaelAsync('~/some_dir');
for (let i = 0; i < domElems.length; ++i) {
domElems[i].addEventListener('click', () => {
console.log(i);
});
}