Skip to content

Instantly share code, notes, and snippets.

View godfat's full-sized avatar

Lin Jen-Shin (godfat) godfat

View GitHub Profile
@godfat
godfat / gist:30606
Created December 1, 2008 03:28
Kernel and IncludedModule
# http://rubinius.lighthouseapp.com/projects/5089/tickets/729-kernel-and-includedmodule
module M
def m
end
end
module K
end
# http://rubinius.lighthouseapp.com/projects/5089/tickets/614-calling-a-class-method-on-an-object-s-metaclass-should-invoke-the-class-method-of-the-object-s-class#ticket-614-5
class Object
# The hidden singleton lurks behind everyone
def metaclass; class << self; self; end; end
def meta_eval(&blk)
metaclass.instance_eval(&blk)
end
# Adds methods to a metaclass
# http://github.com/rtomayko/rack-contrib/commit/f2169bd780c17b4bcc11aacf2d6c1eb6f35bdbee
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.8.7')
class Symbol
def to_proc
lambda{ |*args| args.shift.__send__(self, *args) }
end
end
end
@godfat
godfat / 00000 use case.rb
Created January 6, 2009 09:22
Collection#destroy! and OFFSET/LIMIT
# http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets/746-patch-raise-argumenterror-if-limitoffset-was-set-in-query-in-collectiondestroy
# it's surprising that Collection#destroy! doesn't use LIMIT/OFFSET
require 'rubygems'
require 'dm-core'
class Pet
include DataMapper::Resource
property :id, Serial
end
@godfat
godfat / gist:53367
Created January 27, 2009 14:49
object_pool.hpp.eruby
<% header_guard do %>
#include <boost/pool/object_pool.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#define LOKI_CLASS_LEVEL_THREADING
#include <loki/Singleton.h>
#include <iostream>
template <class T>
class None: public T{
public:
static None<T>* none(){
static None<T> _;
return &_;
}
@godfat
godfat / Star.hs
Created March 14, 2009 16:22
Star
{-
3
345
34567
345
3
-}
module Main where
puts($stdin.read.split(/=/).reject{|a|a=="\n"}.map{|a|a=~/^[0-9A-Z]{2}/?[a[0..1],a[2..-1]]:a}.flatten.reject(&:empty?).map{|a|a=~/^[0-9A-Z]{2}$/?a.to_i(16):a.unpack('c*')}.flatten.pack('c*'))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
<title>test jquery submit event hook</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"/>
<script type="text/javascript">
$(document).ready(function(){
$('#s1').click(function(){
// author:
// http://joshkos.blogspot.com/2009/06/blog-post_13.html
#ifndef GETSET_HPP
#define GETSET_HPP
template<typename T, typename C, T C::* P>
struct Selector { // used for selecting which field to access
static T C::* const MP;
typedef T Type;