Skip to content

Instantly share code, notes, and snippets.

View zbjornson's full-sized avatar

Zach Bjornson zbjornson

View GitHub Profile
@zbjornson
zbjornson / make_specs.rb
Created December 17, 2013 05:28
Designed to rough-out the spec folder of your Ruby on Rails application. For example, you have a ton of models living in WEB-INF/app/models and want WEB-INF/spec/models to have corresponding model_xxx_spec.rb files, complete with the header (e.g. schema, copyright--anything in the top of the file that starts with a #) and "describe #{method}" st…
puts "in #{Dir.pwd}\n"
Dir.entries("app/helpers").each do |file_name|
file_path = "#{Dir.pwd}/app/helpers/#{file_name}"
puts "Processing #{file_name}\n"
unless File.directory?(file_path)
spec_file_name = file_name.sub(/\.rb/, "_spec.rb")
unless File.file?("spec/helpers/#{spec_file_name}")
class_name = nil
@zbjornson
zbjornson / has_lib.js
Created April 24, 2016 19:05
has_lib.sh in javascript for node-canvas
var query = process.argv[2];
var fs = require('fs');
var path = require("path");
var childProcess = require("child_process");
var SYSTEM_PATHS = [
"/lib",
"/usr/lib",
"/usr/local/lib",
"/opt/local/lib",
@zbjornson
zbjornson / node_buffer.asm
Created June 20, 2016 17:51
swap32 without alignment check
void Swap32(const FunctionCallbackInfo<Value>& args) {
00007FF79E253100 push rbx
00007FF79E253102 push rdi
00007FF79E253103 sub rsp,28h
00007FF79E253107 mov rdi,rcx
Environment* env = Environment::GetCurrent(args);
00007FF79E25310A call node::Environment::GetCurrent (07FF79E22D240h)
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
00007FF79E25310F cmp dword ptr [rdi+10h],0
Environment* env = Environment::GetCurrent(args);
@zbjornson
zbjornson / Base.js
Created July 11, 2016 23:41
(SO question) JS for typescript, trying to create generic factory method on base class
"use strict";
var MyNS;
(function (MyNS) {
var Base = (function () {
function Base() {
}
Base.create = function (foo) {
return new MyNS[foo.type]();
};
return Base;
@zbjornson
zbjornson / example.js
Last active August 10, 2016 16:16
SO 5263716
var http = require('http');
var server = http.createServer(function (req, res) {
req.connection.unref(); console.log("Got request. Connection unref'ed again");
res.writeHead(200, {"Content-Type": "text/plain"});
setTimeout(function () {
console.log("Handler timeout invoked");
res.end("Hello", function (err) {;
@zbjornson
zbjornson / colorGradientCalculator.js
Last active August 11, 2016 19:25
First attempt at hand-writing an asm.js module.
// Interpolates through 10 RGB values, given a value and its domain
colorGradientCalculator = function (stdlib, foreign, heap) {
"use asm";
var rgb = new stdlib.Uint8Array(heap);
var imul = stdlib.Math.imul;
var floor = stdlib.Math.floor;
var lowIndex = 0;
var partial = 0.0;
@zbjornson
zbjornson / EmbeddedTLB
Created August 14, 2016 20:35
SO 38945481
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: VWorksCPPATL.dll
[
uuid(83ED4BB2-4E00-4349-AD9E-493801A0FC62),
version(1.0),
custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218331),
custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1471199125),
custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, "Created by MIDL version 8.00.0603 at Sun Aug 14 11:25:24 2016
@zbjornson
zbjornson / github-issues.wl
Last active December 14, 2016 03:20
GitHub Issue Charts in Mathematica
(* Common: *)
ToJSON[x_] := ImportString[FromCharacterCode[x, "Unicode"], "RawJSON"](*Ignore emoji*)
getIssues[repo_] := getIssues[repo, "*"]
getIssues[repo_, milestone_] :=
getIssues[repo, milestone] = Block[{url, head, pageCount, issues},
url = URLBuild[{"https://api.github.com/repos", repo, "issues"},
{"state" -> "all",
(*"access_token" -> "...",*) (* use for private repos, larger API quota*)
"sort" -> "created",
@zbjornson
zbjornson / styler.js
Created May 24, 2017 20:39
Styler utility
/**
* Tool to change styles with dynamic CSS. Use instead of setting style
* properties on individual elements.
*/
function Styler() {
this.styleEl = document.createElement("style");
document.head.appendChild(this.styleEl);
// Map for quickly looking up an existing rule by its selector.
this.ruleMap = new Map();
}
hoistDotArgs = function(fn) {
dotCalls = list()
findDotArgs = function(exp) {
if (typeof(exp) == "closure") { # entry point
expL = as.list(exp)
args = names(expL)
if (!("..." %in% args)) return(invisible()) # no dots to hoist
body = expL[[length(expL)]]
findDotArgs(body)