Skip to content

Instantly share code, notes, and snippets.

@masaki
masaki / gist:1176638
Created August 28, 2011 12:59
direct easy_install
$ sudo easy_install webcolors Searching for webcolors
Reading http://cheeseshop.python.org/pypi/webcolors/
Reading http://www.bitbucket.org/ubernostrum/webcolors/overview/
error: Download error: (-2, 'Name or service not known')
exit 1
$ sudo easy_install http://pypi.python.org/packages/source/w/webcolors/webcolors-1.3.1.tar.gz
Downloading http://pypi.python.org/packages/source/w/webcolors/webcolors-1.3.1.tar.gz
Processing webcolors-1.3.1.tar.gz
Running webcolors-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-HXFg3s/webcolors-1.3.1/egg-dist-tmp-hw4BbL
@masaki
masaki / setup.rake
Created July 27, 2011 00:15
create Rails config files as Rake task
# -*- encoding: utf-8 -*-
namespace :setup do
def copy_config(options = {})
Dir["#{RAILS_ROOT}/**/*.sample", "#{RAILS_ROOT}/**/*.example"].each do |source|
target = source.sub(/\.(ex|s)ample$/, '')
if options[:force] or not File.exist?(target)
require 'fileutils'
puts "Create config file '#{target}' from '#{source}'"
FileUtils.copy_file source, target
@masaki
masaki / rubygems-1.8.5-no_proxy.patch
Created July 20, 2011 12:15
RubyGems NO_PROXY auto-detection without http_configuration gem
--- rubygems-1.8.5/lib/rubygems/remote_fetcher.rb.orig 2011-07-20 00:28:13.000000000 +0900
+++ rubygems-1.8.5/lib/rubygems/remote_fetcher.rb 2011-07-20 01:09:59.000000000 +0900
@@ -69,6 +69,7 @@
when URI::HTTP then proxy
else URI.parse(proxy)
end
+ @no_proxy = (ENV['NO_PROXY'] || ENV['no_proxy'] || 'localhost, 127.0.0.1').split(/\s*,\s*/)
@user_agent = user_agent
end
@masaki
masaki / testmanager_trac0.12_py2.4.patch
Created June 24, 2011 00:55
Trac-0.12 and Python-2.4 patch for "Test Manager plugin for Trac"
--- testman4trac/trunk/testmanager/api.py.orig 2011-06-18 23:16:34.000000000 +0900
+++ testman4trac/trunk/testmanager/api.py 2011-06-23 18:55:13.000000000 +0900
@@ -85,8 +85,10 @@
if row[0] == 'default':
self.default_outcome = row[1].lower()
else:
- color = row[0].partition('.')[0]
- outcome = row[0].partition('.')[2].lower()
+ color = row[0].split('.')[0]
+ outcome = ''
@masaki
masaki / trac-install.sh
Created May 29, 2011 11:48
Trac-0.12 installation
# -*- coding: utf-8 -*-
# file: trac-install.sh
# prepare
yum install sqlite sqlite-devel mod_wsgi
easy_install pysqlite Babel Genshi pytz docutils
# or `yum install python-sqlite2 babel python-genshi pytz python-docutils`
# setup
wget http://www.i-act.co.jp/project/products/downloads/Trac-0.12.2.ja1.zip
@masaki
masaki / trac-xmlrpc-ticket-apply-before-validate.patch
Created May 24, 2011 06:49
Trac XmlRpcPlugin and validate_ticket extension point
diff --git a/tracrpc/ticket.py b/tracrpc/ticket.py
index 6224276..3042718 100644
--- a/tracrpc/ticket.py
+++ b/tracrpc/ticket.py
@@ -237,14 +237,13 @@ class TicketRPC(Component):
req.args['comment'] = comment
req.args['ts'] = time_changed
changes, problems = tm.get_ticket_changes(req, t, action)
- for warning in problems:
- add_warning(req, "Rpc ticket.update: %s" % warning)
@masaki
masaki / gist:713295
Created November 24, 2010 07:55
C++ smart_ptr enabled handle class w/ custom deleter
namespace win32 {
// deleter traits
template <class T> struct handle_deleter_t {
typedef T handle_type;
};
struct win32_handle_deleter : public handle_deleter_t<HANDLE> {
void operator()(handle_type handle) {
if (handle && handle != INVALID_HANDLE_VALUE) ::CloseHandle(handle);
};
};
$ git clone http://git.chromium.org/git/chromium.git chromium-src
Cloning into chromium-src...
remote: Counting objects: 599632, done.
remote: Compressing objects: 100% (125184/125184), done.
remote: Total 599632 (delta 446304), reused 587790 (delta 435692)
Receiving objects: 100% (599632/599632), 1.05 GiB | 311 KiB/s, done.
Resolving deltas: 100% (446304/446304), done.
@masaki
masaki / gist:373769
Created April 21, 2010 12:41
C++ stringstream buffer sample
#include <iostream>
#include <sstream>
#include <vector>
typedef std::vector<char> Buffer;
void assign(std::stringstream& stream) {
Buffer buffer;
buffer.push_back('M');
buffer.push_back('A');
@masaki
masaki / gist:329030
Created March 11, 2010 10:44
OO-ish ab (apache bench)
#!/usr/bin/ruby
require 'stringio'
module AB
class Response
class << self
def parse_string(string)
new.tap {|res| res.parse_string(string) }
end