Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'nokogiri'
require 'open-uri'
class GistID
GIST_URL = 'http://gist.github.com/'
ALL_LIMIT = 10
def initialize user = get_user
@user = (user.nil? || user == :all) ? 'gists' : user
@isaacs
isaacs / comma-first-var.js
Created April 6, 2010 19:24
A better coding convention for lists and object literals in JavaScript
// See comments below.
// This code sample and justification brought to you by
// Isaac Z. Schlueter, aka isaacs
// standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog",
%% A
F = fun() ->
mnesia:table_info(store, size)
end,
Result = mnesia:activity(async_dirty, F, [], mnesia_frag).
%% B
Result = mnesia:activity(async_dirty,
fun() ->
mnesia:table_info(store, size)
@cocoatomo
cocoatomo / mangling.py
Created December 7, 2010 11:38
Python での name mangling の上書き動作
class SecretFirst(object):
def __secret(self):
print('__secret')
def _SecretFirst__secret(self):
print('_SecretFirst__secret')
class SecretSecond(object):
def _SecretSecond__secret(self):
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@maoe
maoe / QCWithGADTs.hs
Created May 3, 2011 18:18
GADTsなデータ型をQuickCheckのArbitraryクラスのインスタンスにする
{-# LANGUAGE FlexibleInstances, ExistentialQuantification, StandaloneDeriving, GADTs #-}
module QCWithGADTs where
import Control.Applicative ((<$>), pure)
import Test.QuickCheck (Arbitrary(..), oneof)
{- FOP: Fun with Phantom Tyepsより
Term tをArbitraryのインスタンスにするには、2つやるべきことがある。
1) 各構成子の結果型が異なる問題を解決する
2) 構成子によって引数の型が異なる型に特殊化されているので、それぞれの型に対応する
@yatsuta
yatsuta / gist:1047733
Created June 26, 2011 16:02
Lisp by R
opt <- options(warn=-1)
## ------------------------------------------------------------
## Test
## ------------------------------------------------------------
## > rm(list=ls()); source("Eval.R")
## > repl()
## rlisp > (<- make.counter (function (c) (function () (<<- c (+ c 1)))))
@hdemon
hdemon / update_by_innerjoin
Created November 18, 2011 10:13
MySQLでは自己相関サブクエリが使えないらしいので、内部結合を使って自分のテーブル内のカラムを集計し、別のカラムに入れる。
UPDATE movie_log
INNER JOIN (
SELECT
item_id,
date,
view +
(
comment *
(
@yumike
yumike / blocks.py
Created December 8, 2011 06:45
Thoughts about RSpec for Python
# codec: blocks
describe('articles.views.ArticleView'):
context('when user has permissions'):
it('should add new article'):
# some code
it('should delete existing article'):