Skip to content

Instantly share code, notes, and snippets.

View chikathreesix's full-sized avatar

Ryo Chikazawa chikathreesix

View GitHub Profile
@chikathreesix
chikathreesix / to_query.rb
Last active August 29, 2015 14:18
Convert from Hash to Rails query
require 'cgi'
def to_query(param, namespace = nil)
case param
when Hash
param.collect do |key, value|
unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
to_query(value, namespace ? "#{namespace}[#{key}]" : key)
end
end.compact.sort! * '&'
@chikathreesix
chikathreesix / .vimrc
Created December 23, 2014 05:09
my vimrc
set runtimepath^=~/.vim/bundle/ctrlp.vim
execute pathogen#infect()
syntax on
filetype plugin indent on
set number
colorscheme torte
set tabstop=2
set shiftwidth=2
set expandtab
@chikathreesix
chikathreesix / gist:02f0a51ae8215b4ed019
Created November 26, 2014 04:43
Regex: swtich ruby's symbol key to string key
%s/^\( *\)\([a-z_]\+\):/\1"\2" =>/
@chikathreesix
chikathreesix / fps_logger.js
Created May 2, 2014 08:46
Logging FPS (frame per second)
(function(global){
var FPSLogger = (function(){
var count = 0;
var time;
var fps = 0;
function start(){
time = Date.now();
count = 0;
}
Raven.config('http://ac7d77fa84aa407a96ae325c4d0b90fe@sentry.example.com:9000/2', {}).install();
window.onerror = function (errorMsg, file, lineNumber, colNumber, error) {
console.log('onerror', error);
var id = Math.floor(Math.random() * 1000)
var email = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
email += possible.charAt(Math.floor(Math.random() * possible.length));
@chikathreesix
chikathreesix / simple_pjax.js
Created February 7, 2014 02:55
Simple Pjax that works in modern browsers
(function(global){
var _isSupported = window.history && window.history.pushState && window.history.replaceState &&
!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/);
function Pjaxer(){
var _callbacks = {};
var _caches = {};
var _target;
initialize.apply(this, arguments);
@chikathreesix
chikathreesix / fibonacci.js
Created January 17, 2014 00:41
The Fibonacci function. Really easy to implement.
function fibonacci(index){
if(index == 0){
return 0;
}else if(index == 1){
return 1;
}
var a = 0, b = 1, value = 0;
for(var i = 1; i < index; i++){
value = a + b;
a = b;
@chikathreesix
chikathreesix / sprite_sheet_generator.rb
Last active January 3, 2016 01:19
Generates a sprite sheet and a css file.
#!/usr/bin/ruby
require 'RMagick'
require 'json'
include Magick
dir_name = ARGV[0]
css_dir = ARGV[1] || 'css/'
img_dir = ARGV[2] || 'img/'
dir_name += '/' unless dir_name =~ /\/$/
#!/usr/bin/ruby
dir_name = ARGV[0]
dir_name += '/' unless dir_name =~ /\/$/
Dir.open(dir_name).each do |f|
p dir_name + f
end
@chikathreesix
chikathreesix / server.rb
Created November 19, 2013 08:57
Simple WEBrick server
require 'webrick'
srv = WEBrick::HTTPServer.new({
:DocumentRoot => '/',
:BinAddress => 'localhost',
:Port => 8888
})
srv.mount('/', WEBrick::HTTPServlet::FileHandler, Dir.pwd, {:FancyIndexing => true})