Skip to content

Instantly share code, notes, and snippets.

@seanchas116
seanchas116 / different_class.rb
Last active August 29, 2015 14:01
A ruby benchmark to simulate method lookup slowdown by dynamic method definition (in Ruby 2.1.2)
require 'benchmark'
class Test
mcount = 1000
mcount.times do |i|
class_eval "def method#{i}; end"
end
@seanchas116
seanchas116 / table.rb
Created August 19, 2014 07:01
こんな書き方したい
tbl = table do
:foo | :bar | :baz
1 | 2 | 3
1 | 3 | 5
end # => [{:foo=>1, :bar=>2, :baz=>3}, {:foo=>1, :bar=>3, :baz=>5}]
tbl2 = table :horizontal do
:foo | 1 | 1
:bar | 2 | 3
:baz | 3 | 5
@seanchas116
seanchas116 / index.js
Created October 3, 2014 13:47
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
var count = 0;
function countup() {
count += 1;
update();
@seanchas116
seanchas116 / index.js
Created October 7, 2014 01:57
requirebin sketch
'use strict';
var h, mainLoop, render, viewLoop, viewModel;
mainLoop = require('main-loop');
h = require('virtual-dom/h');
viewModel = {
count: 0,
countUp: function() {
@seanchas116
seanchas116 / index.js
Created October 30, 2014 12:45
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
function update() {
var newTree = render(counter);
var patches = diff(tree, newTree);
patch(node, patches);
tree = newTree;
@seanchas116
seanchas116 / haml2jade.rb
Last active August 29, 2015 14:22
haml -> jade
Dir.glob("./**/*.haml").each do |haml|
jade = haml.gsub(/\.haml$/, ".jade")
`haml #{haml} --style ugly | html2jade --donotencode --noemptypipe --bodyless > #{jade}`
end
@seanchas116
seanchas116 / test.js
Last active November 6, 2015 03:10
こういうテストフレームワークほしい
import assert from "power-assert";
import tapSpec from "tap-spec";
const test = new Test();
const {describe, it} = test;
describe("foo", () => {
describe(".bar", () => {
it("fetches bar", async () => {
const result = await foo.bar();
@seanchas116
seanchas116 / linecount.rb
Created April 28, 2013 15:05
A Ruby script that just counts the number of lines in a given directory
require 'pathname'
def count_lines(pathname)
count = 0
pathname.each_child do |child|
if child.directory?
count = count + count_lines(child)
@seanchas116
seanchas116 / libc++.rb
Created June 22, 2013 11:58
A libc++ formula for Homebrew Add "-L/usr/local/lib -I/usr/local/lib/c++/v1" to use
require 'formula'
class Libcxx < Formula
homepage 'http://llvm.org/'
url 'http://llvm.org/releases/3.3/libcxx-3.3.src.tar.gz'
sha1 '7bea00bc1031bf3bf6c248e57c1f4e0874c18c04'
def install
cd './lib' do
@seanchas116
seanchas116 / gist:6306349
Last active December 21, 2015 12:29
僕の考えた最弱な言語
x = 5
y = 10
add = (x, y) =>
x + y
end
z = add x, y
times = (i, fn) =>
iteration = (j) =>
switch j < i