Skip to content

Instantly share code, notes, and snippets.

@insoul
insoul / pre-commit
Last active August 29, 2015 13:57
git pre-commit hook to protect debugging code and syntax error
#!/usr/bin/env bash
changed_files=`git status --short | grep '^[AMCU]' | awk '{print $2}' | grep -P '\.(rb|erb)'`
if [ -z "$changed_files" ]; then
exit 0
fi
while read -r file; do
result=`grep -rin 'binding.pry\|debugger' $file`
@insoul
insoul / subp
Last active December 28, 2015 07:39
Make Sublime Text project file using ruby bundler. Project file will be created in upper folder. Check `subp --help`
#!/usr/bin/env ruby
require 'json'
require 'optparse'
# variables
project_name = Dir.pwd.split('/').last
project_file = "../.#{project_name}.sublime-project"
puts "Project file is #{project_file}"
# gem attributes
@insoul
insoul / gist:6917894
Created October 10, 2013 12:57
yield vs block.call vs instance_eval(&block)
class A
def yield_block
yield
end
def call_block(&block)
block.call
end
def eval_block(&block)
@insoul
insoul / gitipe.rb
Last active December 15, 2015 13:39
capistrano recipe for using git file as capistrano recipe
# use recipe on git.
#
# necessary variable: none
#
# optional variable:
# gitipe_repository:
# if this is empty, use source as gitipe
# gitipe_branch:
# if gitipe_repository is not empty, this varaible is not used
# default "master"
@insoul
insoul / db_migrate_force.rake
Created March 24, 2013 13:38
rails schema_migrations table manipulation
namespace :db do
namespace :migrate do
desc 'insert version to migration table directly'
task :force, :version do |t, args|
ActiveRecord::Base.connection.initialize_schema_migrations_table
version = Integer(ENV['VERSION'] || args[:version])
migrations = ActiveRecord::Migrator.migrations(ActiveRecord::Migrator.migrations_paths)
table = Arel::Table.new(ActiveRecord::Migrator.schema_migrations_table_name)
migrated = ActiveRecord::Migrator.get_all_versions
@insoul
insoul / Preferences.sublime-settings.json
Last active December 10, 2015 17:28
Preference for Sublime Text 2. Install Package Control and add next packages. Soda theme and color scheme, SublimeLinter, Git
{
// global settings
"theme": "Soda Light 3.sublime-theme",
"folder_exclude_patterns":
[
".idea",
".bundle",
".git",
"log"
],
@insoul
insoul / .gitconfig
Created September 26, 2012 03:04
git global config
[user]
name = Foo
email = foo@gmail.com
[color]
diff = auto
status = auto
branch = auto
interactive = auto
[merge]
summary = true
@insoul
insoul / commit-msg
Created April 10, 2012 07:14
git commit hook for redmine
#!/usr/bin/env ruby
BASEDIR = ENV["HOME"] + "/.git_redmine"
require BASEDIR + "/git_redmine"
include GitRedmine::Hooks
exit commit_msg(ARGV[0])
@insoul
insoul / install_nginx.sh
Created March 26, 2012 09:29
install nginx
#!/bin/sh
set -x
nginx_version=1.0.9
sudo apt-get install gcc
sudo apt-get install libpcre3-dev
sudo apt-get install libssl-dev
mkdir install_nginx && cd install_nginx
@insoul
insoul / nginx
Created March 26, 2012 09:10
Nginx init script
#!/bin/sh
# File: /etc/init.d/nginx
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6