Skip to content

Instantly share code, notes, and snippets.

View rosylilly's full-sized avatar
🕊️
Happy Hacking

Sho Kusano rosylilly

🕊️
Happy Hacking
View GitHub Profile
class CS5
Pseudo_Classes = [
/root/,
/nth\-child\((\d+n\+\d+|\d+|odd|even)\)/,
/nth\-last\-child\((\d+n\+\d+|\d+|odd|even)\)/,
/nth\-of\-type\((\d+n\+\d+|\d+|odd|even)\)/,
/nth\-last\-of\-type\((\d+n\+\d+|\d+|odd|even)\)/,
/first\-child/,
/last\-child/,
/first\-of\-type/,
@rosylilly
rosylilly / Object_overide.rb
Created February 3, 2009 20:57
Prototype class for ruby
class Object
def method_missing( _method, *arg)
_method = _method.to_sym
if (_method.to_s[_method.to_s.size - 1] == ?=) && ( arg[0].class == Proc)
target = (self.class == Class ? self : self.class)
target.class_eval do
define_method( _method.to_s[0, _method.to_s.size - 1].to_sym, arg[0].binding)
end
else
raise NoMethodError, "undefined method `#{_method}' for #{self.inspect}:#{self.class}", caller(1)
@rosylilly
rosylilly / prototype.rb
Created April 12, 2009 16:41
Prototypical Objects on ruby
class Prototype
def new(member = {}, &block)
prototype(member || {}, self,&block)
end
def respond_to?(name)
return self if methods.include?(name.to_s)
__proto__ = @proto.respond_to?(name)
return __proto__ if __proto__
false
@rosylilly
rosylilly / index.cgi
Created July 5, 2009 03:34
違う、違うんだ。俺が悪いんじゃない。アイツが俺を殺そうとしたから……!
#!ruby path
ENV['GEM_HOME'] = "gem path"
require 'rubygems'
require 'cgi'
require 'RMagick'
require 'kconv'
print "Content-Type: text/html\n\n"
class Object
def self_methods
methods.map{|m|
m=method(m.to_sym)
(m.owner == self.class ? m.name : nil )
}.compact
end
end
p ''.methods.sort
Class.class_eval do
undef :allocate
end
begin
p Class.new
rescue => e
p e
end
# => <Class:0x*******>
#nil# Public local sketchbook
Desktop Templates log src
Documents Videos obj themes
Examples bin page-speed-images tmp
Firefox_wallpaper.png dev page-speed-javascript デスクトップ
Music hsptmp salasaga 編集中のドキュメント 1
Pictures j602 server
@rosylilly
rosylilly / atmark_variables.rb
Created October 8, 2009 10:58
理解不能
class Foo
@baz = 1
@@bar = 2
def self.baz; @baz; end
def self.baz=(n); @baz=n; end
def self.bar; @@bar; end
def self.bar=(n); @@bar=n; end
end
class Hoge < Foo
# 実現したいこと
puts "0"
# Golf
p 0
# 縛り
# 英数字禁止
$><<"#$.#$/"
class Array
def nindex(n)
p self
_index = self.index(n)
if _index.nil?
return []
else
if _index == (self.size - 1)
return [_index]
else