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 fs = require('fs'); | |
const path = require('path'); | |
const entry = 'src\\index.js'; | |
const importRegex = /^import.+?from ['"]([^'"]+)['"];?\s*$/gm; | |
function resolve(name) { | |
try { |
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
extern crate rustc_serialize; | |
use std::io; | |
use rustc_serialize::json::Json; | |
fn main() { | |
loop { | |
let mut input = String::new(); | |
io::stdin().read_line(&mut input).unwrap(); |
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
// Pragmatic typed immutable.js records using typescript 2.1+ | |
// Comment with any suggestions/improvements! | |
import * as fs from 'fs' | |
import { Record, Map } from 'immutable' | |
type Stats = fs.Stats; | |
// Define the basic shape. All properties should be readonly. This model | |
// defines a folder because it seemed easy C: |
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
// __tests__/example.js | |
jest.mock('fs'); | |
it('should serve as a nice example', () => { | |
const fs = require('fs') | |
// fs can be set up at any point by calling __configureFs. | |
fs.__configureFs({ | |
'/test': { |
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
func pingDatabase(db *sql.DB, seconds int) { | |
errc := make(chan error, 1) | |
go func() { | |
errc <- db.Ping() | |
}() | |
select { | |
case err := <-errc: | |
return err | |
case <-time.After(time.Second * seconds): |
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 Tapable = require("tapable"); | |
Tapable.prototype.plugin = function plugin(name, fn) { | |
if(Array.isArray(name)) { | |
name.forEach(function(name) { | |
this.plugin(name, fn); | |
}, this); | |
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
// Source data | |
var exampleData = [ | |
{ | |
id: 1, | |
first: 'Janice', | |
last: 'Howell', | |
}, | |
{ | |
id: 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
export default class WebStorage { | |
constructor(key, storageArea = window.localStorage) { | |
this.key = key; | |
this.storageArea = storageArea; | |
} | |
load(defaultValue) { | |
const serialized = this.storageArea.getItem(this.key); | |
return serialized === null ? defaultValue : this.deserialize(serialized); | |
} |
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
export default function History(initialState) { | |
this.reset(initialState); | |
} | |
History.prototype = { | |
reset: function(initialState) { | |
this.history = [initialState]; | |
this.pointer = 0; | |
this.tail = 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
/** | |
* For limiting concurrency, Javascript style. | |
* | |
* Created for a document viewer; basically a number of thumbnails and | |
* a full image of the current page. "Changing the page" entailed | |
* changing the src of the full image, and the expectation was for that | |
* page to load. However, the thumbnails would saturate the browser's | |
* download limit, so the page wouldn't change until _all_ of the | |
* thumbnails had finished downloading. With 300+ page documents and |