Skip to content

Instantly share code, notes, and snippets.

View hoshinotsuyoshi's full-sized avatar
🍫
alive

hoshino tsuyoshi hoshinotsuyoshi

🍫
alive
View GitHub Profile
@agnellvj
agnellvj / friendly_urls.markdown
Created September 11, 2011 15:52 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@danbronsema
danbronsema / rspec performance test
Created December 9, 2011 12:06
Performance testing in Rspec
context 'performance' do
before do
require 'benchmark'
@posts = []
@users = []
8.times do |n|
user = Factory.create(:user)
@users << user
aspect = user.aspects.create(:name => 'people')
connect_users(@user, @aspect0, user, aspect)
@brutuscat
brutuscat / index.json.haml
Created February 14, 2012 09:59
Rails HAML Json render
:plain
[
- @movies.each do |movie|
:plain
{
"name":"#{movie.name}",
"description":"#{j(movie.description)}"
},
]
@granolocks
granolocks / ifconfig.rb
Created April 23, 2012 14:26
Simple Ifconfig Parser in Ruby
class IfconfigParser
MAC_REGEX = /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/
# NOTE: this has some slightly weird results for wlan interfaces. Really meant to be used for eth0
def self.ifconfig(iface)
output = Hash.new
ifconfig_string = `ifconfig #{ iface }`
ifconfig_string.gsub!("RX ", "RX_")
ifconfig_string.gsub!("TX ", "TX_")
@nixpulvis
nixpulvis / gem-reset
Last active October 5, 2020 15:21
Remove all non default gems. For ruby 2.0.0
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
@hiono
hiono / remove-ansi-escape-sequence
Last active July 8, 2022 11:31
ANSIエスケープシーケンスを除去する
alias rmescseq='sed -r "s:\x1B\[[0-9;]*[mK]::g"'
@tcnksm
tcnksm / Dockerfile
Last active August 29, 2015 13:57
Example of rbdock
FROM tcnksm/rails_base
# swith to sudo
sudo -i
# create swap
touch /2GiB.swap
chattr +C /2GiB.swap
fallocate -l 2048m /2GiB.swap
chmod 600 /2GiB.swap
mkswap /2GiB.swap
@hagiyat
hagiyat / wercker.yml
Last active April 8, 2016 14:50
test-queue on wercker
# only run spec
box: nanapi/ubuntu-rvm-with-phantomjs@0.0.2
no-response-timeout: 10
services:
- ibash/mysql5.6
build: