Skip to content

Instantly share code, notes, and snippets.

View zenizh's full-sized avatar

Hiroki Zenigami zenizh

View GitHub Profile
@zenizh
zenizh / pundit.rb
Last active May 14, 2018 19:16
Authorize resource with Pundit gem
def authorize_user(record = nil)
record ||= controller_name.classify.constantize
authorize record, "#{action_name}?"
end
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@zenizh
zenizh / .rb
Last active January 26, 2018 13:54
class SearchForm
def initialize(posts)
@posts = posts
end
def search
# posts = とすると posts がローカル変数になるので nil になる
posts = posts.where ...
# attr_reader を public に定義すれば次のように書けるが不必要に公開したくない
@zenizh
zenizh / main_test.go
Last active December 11, 2017 10:44
main_test.go
package main
import (
"fmt"
"os"
"github.com/kami-zh/go-capturer"
)
func ExampleCaptureStdout() {
@zenizh
zenizh / Rails勉強会@東京93ぽじぺ.md
Last active December 4, 2017 01:35
Rails勉強会@東京93ぽじぺ.md
@zenizh
zenizh / structural_type_check.rb
Last active September 19, 2017 02:48
Structural Type Check
class Class
def conform?(klass)
(klass.instance_methods - instance_methods).empty?
end
end
module Foo
def bar; end
def baz; end
end
@zenizh
zenizh / guessing_game.rs
Created May 21, 2017 08:36
Rust 数当てゲーム
extern crate rand;
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
@zenizh
zenizh / nginx.conf
Created October 13, 2016 21:55
nginx configuration (SSL disabled)
user nginx;
worker_cpu_affinity auto;
worker_processes auto;
worker_rlimit_nofile 4096;
error_log /var/log/nginx.error.log;
pid /var/run/nginx.pid;
events {
@zenizh
zenizh / nginx.conf
Created October 13, 2016 21:53
nginx configuration (SSL enabled)
user nginx;
worker_cpu_affinity auto;
worker_processes auto;
worker_rlimit_nofile 4096;
error_log /var/log/nginx.error.log;
pid /var/run/nginx.pid;
events {
@zenizh
zenizh / unicorn.rb
Created October 11, 2016 04:19
An example of unicorn.rb
current_path = '/path/to/app/current'
shared_path = '/path/to/app/shared'
worker_processes 4
working_directory current_path
listen "#{shared_path}/tmp/sockets/.unicorn.sock"
pid "#{shared_path}/tmp/pids/unicorn.pid"