Skip to content

Instantly share code, notes, and snippets.

View shelling's full-sized avatar

shelling shelling

View GitHub Profile
#!/usr/bin/env ruby
def integer?(number)
(number % 1) == 0
end
def double_square_number?(number)
sqrt = Math.sqrt(number)
if integer?(sqrt)
[sqrt.to_i, 0]
#!/usr/bin/env ruby
class String
def *(str)
maxshift = self.length + str.length - 2
results = Array.new(maxshift+1, 0)
self.split(//).map(&:to_i).each_with_index do |i, at1|
@shelling
shelling / gist:93627
Created April 11, 2009 17:02
getting start with DataMapper
#!/usr/bin/env ruby
# simple connect to database with DataMapper
require "rubygems"
require "data_mapper"
DataMapper.setup(
:default,
"sqlite3:///tmp/dm-core.sqlite3"
)
@shelling
shelling / gist:94519
Created April 13, 2009 16:37
an example shows how to customize jifty application layout
package JiftyTest::View::Page;
use base Jifty::View::Declare::Page;
use Jifty::View::Declare::Helpers;
# use base qw(Jifty::Plugin::ViewDeclarePage::Page);
# This plugins is used for replace Jifty::View::Declare::Page
# try it later
use Class::Trigger;
@shelling
shelling / gist:95787
Created April 15, 2009 14:06
an example shows how to initialize more instance variable of Array object
#!/usr/bin/env ruby
# shelling
# This script show how to initialize more instance variables when creating an Array object
class Array
attr_reader :this
def initialize
super
@this = 0
@shelling
shelling / gist:96403
Created April 16, 2009 13:06
catch enrollment tidings from NTU ACA and render rss
#!/usr/bin/env perl
# shelling <shelling@cpan.org>
# This script can get enrollment tidings(招生資訊)
# from 台灣大學教務處(NTU ACA) and render rss list
use utf8;
no warnings;
use CGI::RSS;
use pQuery;
use LWP::Simple;
@shelling
shelling / gist:97157
Created April 17, 2009 17:52
render ActiveRecord instance as form
module ActiveRecord
module Render
module From
def render_as_form
res = String.new
obj = self.class.to_s.downcase.to_sym
self.class.columns.each do |c|
#!/usr/bin/env perl
#
# author: shelling <shelling@cpan.org>
#
# This script is used to help Jifty Application
# to insert primitive data into database
use lib "lib";
use Jifty;
use Jifty::Everything;
#!/usr/bin/env perl
#
# shelling <shelling@cpan.org>
#
# First KiokuDB example
use KiokuDB;
package Person;
use Moose;
#!/usr/bin/env ruby
require "net/ftp"
require "yaml"
config = YAML::load_file(File.expand_path("~/.passwd"))["localhost"]
Net::FTP.open(config["host"], config["user"], config["pass"]) do |ftp|
ftp.passive = true