Skip to content

Instantly share code, notes, and snippets.

@quanon
quanon / import_csv.rb
Created June 15, 2012 02:31
Import My CSV Data
require 'csv'
namespace :users do
desc 'Import users from a CSV file'
task :import => :environment do
path = ENV.fetch('CSV_FILE') {
File.join(File.dirname(__FILE__), *%w[.. .. db data users.csv])
}
CSV.foreach(path, headers: true, header_converters: :symbol) do |row|
User.create(row.to_hash)
@quanon
quanon / application.yml
Created June 18, 2012 05:44
大学毎に RAILS_ENV を設定
homura_univ_development:
<<: *defaults
application_server_host: 'localhost:3000'
teacher_practice_max_num: 3
registration_is_editable: false
homura_univ_test:
<<: *defaults
application_server_host: 'localhost:3000'
teacher_practice_max_num: 3
@quanon
quanon / kashi_time.user.js
Last active November 18, 2017 16:56
「歌詞タイム」(http://www.kasi-time.com/) の歌詞を ○○○ するための Greasemonkey ユーザスクリプト
// ==UserScript==
// @name kashi time
// @namespace quanon
// @include http://www.kasi-time.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
// @grant none
// ==/UserScript==
(function ($) {
var $lyrics = $('#lyrics'),
#!/bin/sh
# ファイルをゴミ箱に捨てるためのコマンド rmtrash をインストールしておくこと。
# $ brew install rmtrash
# Mac の Downloads ディレクトリ
downloads_dir="/Users/quanon/Downloads/"
# 隠しファイルを除いたファイル数
# grep で隠しファイルを除外する。
@quanon
quanon / extensions.rb
Created April 4, 2014 08:00
過去の遺物
##
# オープンクラスにインクルードさせるためのモジュール集
#
module Extensions
module Hash
##
# Hash の入れ子から値を取り出すためのインスタンスメソッド。
#
# (例)
@quanon
quanon / pictan.rb
Last active August 29, 2015 14:00
ターミナルで Gif アニメを表示する。
#!/usr/bin/env ruby
require 'curses'
require 'rmagick'
require 'pry'
require 'pry-debugger'
def clear_screen
puts "\e[H\e[2J"
@quanon
quanon / falling_yuno
Last active August 29, 2015 14:00
空からゆのっち
$ ruby -e 'Y="X / _ / X";S=Y.size;C=`stty size`.scan(/\d+/)[1].to_i/S;a={};c={};puts "\033[2J";loop{r=rand(C);a[r]=0;c[r]=[*30..37].sample;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x*S+1}H#{" "*S}\033[#{c[x]}m\033[#{a[x]};#{x*S+1}H#{Y}\033[0;0H\033[0m"};$stdout.flush;sleep 0.05}'
@quanon
quanon / gist:4c4957ae74b27a917a5e
Last active August 29, 2015 14:03
GIFアニメを検索してブラウザで開く
curl `ruby -r uri -e 'puts URI.escape("http://ajax.googleapis.com/ajax/services/search/images?rsz=8&v=1.0&safe=active&as_filetype=gif&imgsz=large&as_sitesearch=tumblr.com&q=ひだまりスケッチ")'` | jq '.responseData.results[].url' | peco | xargs open
@quanon
quanon / .zshrc
Last active August 29, 2015 14:03
peco でコマンド履歴を選択する
# peco
function peco-select-history () {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
BUFFER=$(\history -n 1 | \
eval $tac | \
@quanon
quanon / gist:97d665ea58fd8ba5ecd0
Created June 27, 2014 16:37
zsh での function の書き方
# コマンドのまとまりを記述、hogeがコマンド名になる
function hoge () {
echo command
}
# ラインエディタを有効にする。自分が新しいコマンドを作る場合に必要
zle -N hoge
# キーバインドを設定
bindkey '^a' hoge