Skip to content

Instantly share code, notes, and snippets.

@heyimalex
heyimalex / unimported.js
Created January 31, 2017 17:51
Hacky script to find un-imported files
const fs = require('fs');
const path = require('path');
const entry = 'src\\index.js';
const importRegex = /^import.+?from ['"]([^'"]+)['"];?\s*$/gm;
function resolve(name) {
try {
@heyimalex
heyimalex / compress.js
Last active June 18, 2019 19:07
CRA build with gzip
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const async = require("async");
const zlib = require("zlib");
function gzipFile(src, callback) {
console.log(`Compressing ${src}`);
const dst = `${src}.gz`;
fs.createReadStream(src)
@heyimalex
heyimalex / rust-js.md
Created March 13, 2019 07:09
Looking at npm projects that are good candidates for being re-written in rust / webassembly!
@heyimalex
heyimalex / batchchan.go
Created September 21, 2018 20:01
batching channel implementation
package batchchan
import "github.com/cheekybits/genny/generic"
import (
"fmt"
)
type T generic.Type
@heyimalex
heyimalex / Selectize.jsx
Created August 15, 2014 17:30
React wrapper around Selectize.js
/** @jsx React.DOM */
// Wrapper around the selectize jQuery plugin.
module.exports = React.createClass({
getDefaultProps: function() {
return {
// HTML attrs
disabled: false,
multiple: false,
@heyimalex
heyimalex / react-promise-state.js
Last active July 14, 2017 05:46
Helper for dealing with promise-y state in React.js
const PENDING = 0;
const FULFILLED = 1;
const REJECTED = 2;
function PromiseState(component, stateKey, initial) {
this.component = component;
this.stateKey = stateKey;
var self = this;
@heyimalex
heyimalex / reselect-map-types-gen.js
Last active May 22, 2017 12:07
reselect-map typescript types
function genSelectorType({ count, isParametric, isArraySelector }) {
const rmap = fn => {
const results = [];
for (let i = 2; i <= count; i++) {
results.push(fn(i));
}
return results;
};
@heyimalex
heyimalex / jsonpp.rs
Created November 23, 2016 19:28
Streaming json pretty printer
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();
@heyimalex
heyimalex / pingdb.go
Created May 31, 2016 19:31
Ping database with timeout in go
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):
@heyimalex
heyimalex / trackable.js
Created January 13, 2016 23:35
Monkey patches webpack/tapable with some debug information
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;
}