Skip to content

Instantly share code, notes, and snippets.

View todesking's full-sized avatar
💀

todesking todesking

💀
View GitHub Profile
gem "fastimage", "~>1.2.13"
module ApplicationHelper
include ActionView::Helpers::AssetTagHelper
# 画像サイズ見て自動でwidth/height属性つけるimage_tag
def image_tag_with_auto_size(source, options)
if options[:size] || options[:width] || options[:height]
image_tag_without_auto_size(source, options)
else
# config/environments/development.rb
# ActiveRecord 3.2.8 / mysql2 0.3.11
Application.configure do
config.after_initialize do
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
def execute_with_warning_is_error(sql, *rest)
result = execute_without_warning_is_error(sql, *rest)
warnings = execute_without_warning_is_error('show warnings', :skip_logging).to_a
Application.configure do
config.after_initialize do
# Partialの情報をHTMLに埋める
# For ActionPack 3.2.8
class ActionView::PartialRenderer
def render_with_partial_annotation(*args)
setup(*args)
path = @path
content = "".html_safe
# -*- coding: utf-8 -*-
# まだテーブル構造がちゃんと決まってないので、データをコード内にベタ書きしてある。
# 将来的にはActiveRecord化してDBに保存したい。
class NewModel
def self.find(id)
INSTANCES[id] || (raise "not found")
end
INSTANCES = {
@todesking
todesking / svn-cherry-pick.rb
Created August 3, 2012 11:26
svn-cherry-pick
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
raise <<EOS
MOVED: https://github.com/todesking/svn-cherry-pick
EOS
@todesking
todesking / likestorm.rb
Created March 31, 2012 08:11
likestorm
require 'net/http'
def hsv_to_rgb(h, s, v)
h_i = (h*6).to_i
f = h*6 - h_i
p = v * (1 - s)
q = v * (1 - f*s)
t = v * (1 - (1 - f) * s)
r, g, b = v, t, p if h_i==0
r, g, b = q, v, p if h_i==1
r, g, b = p, v, t if h_i==2
@todesking
todesking / .gitconfig
Last active September 27, 2015 22:07
my git command alias
[alias]
alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t => \\2/' | sort
a = add
a-i = add -i
a-p = add -p
co = checkout
b = branch
k = !gitk --all --max-count=200 &
s = status -sb
ci = commit
public enum A {
Hoge(CONST); // Cannot reference a field before it is defined
private static int CONST = 1;
private A(int x) {
}
}
public enum B { // Syntax error on token "{", ; expected after this token
private static int CONST = 1;
Hoge(CONST);
/* 自分で定義したDateRange型から、where条件を生成したい */
-- before
select * from table
where
update_time between /*range.getStart()*/'2011-01-01' and /*range.getEnd()*/'2011-12-31'
-- after
select * from table
where
@todesking
todesking / gist:1188031
Created September 2, 2011 06:30
my PS1 for bash
function __show_errorcode() {
ERR=$?
if [ $ERR != 0 ]; then
echo -en "\033[31m\$?=$ERR"
fi
}
function __show_jobs() {
JOBS=$(jobs|sed 's/ \+/\t/g'|cut -f1,3|tr \\t :|tr \\n ','|sed 's/,$//'|sed 's/,/, /g')
if [ "$JOBS" != "" ]; then