Skip to content

Instantly share code, notes, and snippets.

Avatar

Masahiro Nishimi mahm

View GitHub Profile
@mahm
mahm / hello.txt
Created Mar 31, 2020
for Elm Hands-on
View hello.txt
Hello, world!
View kramdownable.rb
module Kramdownable
extend ActiveSupport::Concern
include ActionView::Helpers::TextHelper
def autolink_filter(content)
auto_link(content, html: {target: '_blank'}, sanitize: false)
end
def kramdown
Kramdown::Document.new(body || '', kramdown_options)
@mahm
mahm / sprockets_ext.rb
Created Nov 27, 2014
Rails3.1 + Ruby2.0 with Sprockets
View sprockets_ext.rb
# Rails 3.2.13以前のバージョン + Ruby2.0の組み合わせだと適切にDirectiveをパースできない不具合がある
# ref: https://github.com/sstephenson/sprockets/issues/352
directive_pattern = /
^ \W* = \s* (\w+.*?) (\*\/)? $
/x
Sprockets::DirectiveProcessor.class_eval do
remove_const(:DIRECTIVE_PATTERN)
const_set(:DIRECTIVE_PATTERN, directive_pattern)
def directives
@mahm
mahm / sample.jmx.rb
Created Nov 23, 2014
ruby-jmeter sample
View sample.jmx.rb
require 'ruby-jmeter'
test name: 'JMX Sample' do
threads count: 5, loops: 5 do
cookies
visit name: 'Login Page', url: 'http://0.0.0.0:3000/users/sign_in' do
extract name: 'csrf-token', xpath: "//meta[@name='csrf-token']/@content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[@name='csrf-param']/@content", tolerant: true
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
@mahm
mahm / Gemfile
Last active Aug 29, 2015
AngularJS & Rails
View Gemfile
source 'https://rubygems.org'
gem 'rails', '4.1.7'
gem 'pg', group: :production
gem 'rails_12factor', group: :production
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.0'
gem 'enumerize'
gem 'inherited_resources'
@mahm
mahm / projects_controller.rb
Last active Aug 29, 2015
AngularJS + Railsでネストしたリソースを取得する
View projects_controller.rb
class ProjectsController < ApplicationController
def index
@projects = Project.all
end
def show
@project = Project.find(params[:id])
end
end
@mahm
mahm / ruby_vs_mongo.rb
Last active Aug 29, 2015
Ruby vs MongoDB
View ruby_vs_mongo.rb
require 'benchmark'
require 'mongo'
def generate_parts(size)
area_patterns = [['main'], ['sub'], ['header', 'footer']]
enable_patterns = [true, false]
level_patterns = ['/level1', '/level1/level2', '/level1/level2/level3']
(1..size).map do |n|
{
@mahm
mahm / benchmark.rb
Last active Aug 29, 2015
'each commit' vs 'transaction' vs 'bulk_insert'
View benchmark.rb
require 'benchmark'
def each_commit(size)
project = Project.create!(name: "each_commit #{size}")
size.times.with_index(1) do |_, index|
project.tasks.create!(name: "Task #{index}")
end
end
def transaction(size)
@mahm
mahm / normal_vs_lazy_1.rb
Last active Aug 29, 2015
normal select vs lazy select
View normal_vs_lazy_1.rb
require 'benchmark'
def normal_selector(array, word)
array.select{|hash| hash[:name].match "#{word}"}.to_a
end
def lazy_selector(array, word)
array.lazy.select{|hash| hash[:name].match "#{word}"}.to_a
end
@mahm
mahm / blog_sample01.rb
Last active Aug 29, 2015
2014/11/12のブログ記事のサンプルコード
View blog_sample01.rb
class Post
def initialize(title, body)
@title, @body = title, body
end
def render
<<-EOS
<article>
<h1>#{@title}</h1>
<p>#{@body}</p>
You can’t perform that action at this time.