Skip to content

Instantly share code, notes, and snippets.

Yusaku Hashimoto nonowarn

Block or report user

Report or block nonowarn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View bench.rb
require "benchmark"
class Array
def duplicates_reject_uniq
reject { |e| count(e) <= 1 }.uniq
end
def duplicates_uniq_reject
uniq.reject { |e| count(e) <= 1 }
end
View by.js
(function (win, doc) {
var by = {}, slice = [].slice, type2method = {
id: "getElementById",
className: "getElementsByClassName",
tagName: "getElementsByTagName",
query: "querySelectorAll"
};
for (var type in type2method) if (type2method[type] in doc) (function (type, method) {
by[type] = method.match(/(?:Elements|All)/) ? function () {
View getargv.c
/* Copied, Pasted and summarized from ps' source code.
You can use sysctl to get other process' argv.
*/
#include <sys/sysctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pid_of(pproc) pproc->kp_proc.p_pid
View comparing.rb
class Proc
def on(g)
f = self
-> a, b { f[g[a], g[b]] }
end
end
class Symbol
def to_func
-> this, *args { this.__send__ self, *args }
View Strange.hs
instance Fractional Integer where
fromRational x = 0
instance Fractional Int where
fromRational x = 1
a :: Int
a = 0
b :: Fractional a => a
View Strange.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
data N = A | B | C | D
instance Num N where
fromInteger 0 = C
fromInteger 1 = B
A + B = B
A + C = C
A + D = B
@nonowarn
nonowarn / h.rb
Created May 3, 2010
javascript-like Hash in Ruby
View h.rb
class H
def initialize(hash) @hash = hash end
def method_missing(name, *args)
if name =~ /([^=]+)=$/
return @hash[$1.intern] = args.first
end
@hash[name] || @hash[name.to_s]
end
end
@nonowarn
nonowarn / TypeEq.hs
Created Mar 2, 2010
Equality on Types
View TypeEq.hs
-- based on http://okmij.org/ftp/Haskell/de-typechecker.lhs
{-# LANGUAGE IncoherentInstances,UndecidableInstances #-}
data HTrue
data HFalse
instance Show HTrue where show _ = "HTrue"
instance Show HFalse where show _ = "HFalse"
View Points.hs
import Data.Has
import Control.Applicative
data X = X; data Y = Y; data Z = Z
newtype Point2D = P2 (X :> Int :&: Y :> Int)
deriving (Has (X `Labelled` Int),Has (Y `Labelled` Int))
getXY :: (Knows X Int p, Knows Y Int p) => p -> (Int,Int)
getXY = liftA2 (,) (prjl X) (prjl Y)
@nonowarn
nonowarn / Makefile
Created Feb 11, 2010
Brainf**k Interpreter
View Makefile
bf: bf.hs
ghc --make -O2 bf
You can’t perform that action at this time.