Skip to content

Instantly share code, notes, and snippets.

View murajun1978's full-sized avatar
🍻

murajun1978 murajun1978

🍻
  • GEEX
  • Japan
View GitHub Profile
@murajun1978
murajun1978 / fetchClient.js
Last active June 5, 2019 17:33
Functional programming in JavaScript
const fetch = require("node-fetch");
export const fetchClient = baseUrl => endpoint => (success, failure) => {
fetch(baseUrl + endpoint)
.then(res => res.json())
.then(success)
.catch(failure);
};
require 'benchmark/ips'
hash_array = (1..10000).map{|n| {name: "foo#{n}"}}
Benchmark.ips do |x|
x.time = 100
x.report("reverse") do
hash_array.sort_by!{|v| v[:name]}
hash_array.reverse!
DIR="$HOME/dev"
tmux new-session -d -s project_name -n processes
tmux send-keys 'top' 'C-m'
tmux split-window -v
tmux send-keys 'top' 'C-m'
tmux split-window -h
tmux send-keys 'top' 'C-m'
tmux new-window -n vim -c "$DIR"
tmux send-keys 'vim' 'C-m'
tmux attach -t project_name
@murajun1978
murajun1978 / current_file.rb
Created October 10, 2014 15:15
__FILE__と$0の違い
require_relative 'require_file'
include RequireFile
$0 # => "current_file.rb"
__FILE__ # => "current_file.rb"
__LINE__ # => 6
File.expand_path(__FILE__) # => "path/to/current_file.rb"
stdout_method
# $0 # => "current_file.rb"
あいて = %w(ぐー ちょき ぱー)
じゃんけん = { :"ぐー" => 0,
:"ちょき" => 1,
:"ぱー" => 2}
loop do
print 'じゃんけん... :'
ぷれいやーの手 = gets.chomp
posts = Post.all
Benchmark.bm do |x|
x.report(:exists) {posts.exists?}
x.report(:present) {posts.present?}
end
user system total real
Post Exists (0.3ms) SELECT 1 AS one FROM "posts" LIMIT 1
exists 0.020000 0.000000 0.020000 ( 0.028894)
@murajun1978
murajun1978 / array_benchmark .rb
Created September 6, 2014 14:00
Arrayのベンチマーク
require 'benchmark'
require 'set'
array = Array.new(1_000_000){[1, 2, 3]}
set = array.to_set
Benchmark.bm(15) do |x|
x.report('array:') { array.each do |n| n.include?(3) end }
x.report('set:') { set.each do |n| n.include?(3) end }
end
@murajun1978
murajun1978 / after2_session_controller.rb
Last active August 29, 2015 14:05
気持ち悪いコード
def create
# リファクタリング後
@staff = Staff.new(params[:staff])
if staff = Staff.find_by(email: @staff.email)
session[:staff_id] = staff.id
redirect :root
else
render :new
end
box: inwy/ubuntu12.04-ruby2.1.2@0.1.0
services:
- wercker/postgresql
build:
steps:
- bundle-install
- rails-database-yml:
service: postgresql
- script:
name: echo ruby information
class Murajun
def initialize(name)
@name = name
end
def murajun?
@name == "murajun"
end
end