Skip to content

Instantly share code, notes, and snippets.

@kinopyo
kinopyo / memcache_test.php
Created June 2, 2011 05:05
MySQL/Oracle/Memcache/Memcached connection test code for PHP
<?php
// memcache test code
$memcache = memcache_connect('127.0.0.1', 11211);
if ($memcache) {
$memcache->set("str_key", "String to store in memcached");
var_dump($memcache->get('str_key'));
}
@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 / nokogiri_https.rb
Created June 21, 2011 08:58
nokogiri parse https url
require 'net/https'
require 'nokogiri'
url = "https://example.com"
url = URI.parse( url )
http = Net::HTTP.new( url.host, url.port )
http.use_ssl = true if url.port == 443
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if url.port == 443
path = url.path
path += "?" + url.query unless url.query.nil?
@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 / ruby_http_post.rb
Created June 24, 2011 06:04
Pure ruby code posting form data with parameters, and get the response.
require 'net/http'
require 'uri'
#1: Simple POST
res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
{'q' => 'ruby', 'max' => '50'})
puts res.body
#2: POST with basic authentication
res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'),
@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 / gist:1062397
Created July 3, 2011 17:17
How to install coffee-script, and how to enable textmate bundler to compile coffeescript
# don't forget to update your port tree first
sudo port selfupdate
# install coffee script using macport
sudo port install nodejs
node -v
# install npm - the Node Package Manager
git clone http://github.com/isaacs/npm.git
cd npm