Skip to content

Instantly share code, notes, and snippets.

@kinopyo
kinopyo / PEAR::HTTP_Request.php
Created June 8, 2011 11:50
PEAR::HTTP_Request usage sample code
<?php
// Some sample codes
// For more information, see http://pear.php.net/manual/en/package.http.http-request.php
require_once "HTTP/Request.php";
// request url
$url = "http://www.example.com";
$option = array(
@kinopyo
kinopyo / Gemfile
Created June 8, 2011 13:37
heroku cedar app rails 3.1rc
### in Terminal
# create rails app
rails new test_app
############ start: edit Gemfile ##############
#wrap sqlite3 in
group :test, :development do
gem 'sqlite3'
end
@kinopyo
kinopyo / mysql_connect.rb
Created June 13, 2011 01:19
MySQL connection test code for Ruby
# mysql_connect.rb - simple MySQL script using Ruby MySQL module
require "mysql"
begin
# connect to the MySQL server
dbh = Mysql.real_connect("localhost", "testuser", "testpass", "testdb")
# get server version string and display it
puts "Server version: " + dbh.get_server_info
@kinopyo
kinopyo / gist:1039656
Created June 22, 2011 07:43
How to add memcached gem(Dalli) to Heroku with Sinatra
# Herodu Dev Center Doc:
# http://devcenter.heroku.com/articles/memcache
# Dalli gem heroku url:
# https://github.com/mperham/dalli
#######################
# Local Setup memcached
#######################
sudo port install memcached
@kinopyo
kinopyo / up_tm_bundles.sh
Created June 26, 2011 07:02
Shell script to update all your textmate bundles
#!/usr/bin/env bash
mkdir -p /Library/Application\ Support/TextMate/
sudo chown -R $(whoami) /Library/Application\ Support/TextMate
cd /Library/Application\ Support/TextMate/
if [[ -d Bundles/.svn ]] ; then
cd Bundles && svn up
@kinopyo
kinopyo / count_of_google_reader_subscribers
Created June 29, 2011 04:39 — forked from moyashi/count_of_google_reader_subscribers
Count of Google Reader subscribers
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'rexml/document'
require 'mechanize'
# ------------------------
YOUR_GOOGLE_ACCOUNT = 'your@gmail.com'
@kinopyo
kinopyo / 2_methods_benchmark.rb
Created September 6, 2011 01:22
Here're code snippets from the book: Metaprogramming in Ruby.
#---
# Excerpted from "Metaprogramming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/ppmetr for more book information.
#---
# the benchmark shows that ghost_reverse( ) is about twice as slow as reverse( )
@kinopyo
kinopyo / solution_1.rb
Created September 9, 2011 01:20
It shows how to enhance ruby class by define a new method to String class. This is just for study.
class String
def sex_code
if ["male", "男"].include? self
0
elsif self == "女"
1
else
self
end
end
@kinopyo
kinopyo / production.rb
Created September 24, 2011 09:25
Asset Pipeline settings in production.rb
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
@kinopyo
kinopyo / rspec_shared_context_example.rb
Created October 13, 2011 10:08
rspec shared_context sample codes.
shared_context "shared stuff" do
before { @some_var = :some_value }
def shared_method
"it works"
end
let(:shared_let) { {'arbitrary' => 'object'} }
subject do
'this is the subject'
end
end