Skip to content

Instantly share code, notes, and snippets.

View ypresto's full-sized avatar
🏠
Working from home

Yuya Tanaka ypresto

🏠
Working from home
View GitHub Profile
#autoload +X
__git_files () {
local expl
_wanted files expl 'file' _files
}
@clemens
clemens / tmpdir.rb
Created November 25, 2010 09:39
Set environment variable so that Dir::tmpdir uses another temp directory
require 'fileutils'
# force the whole app to use its own tmpdir
FileUtils.mkdir_p(Rails.root.join('tmp'))
ENV['TMPDIR'] = Rails.root.join('tmp')
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
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.

@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active April 2, 2024 15:59
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@Gab-km
Gab-km / github-flow.ja.md
Last active April 25, 2024 04:01 — forked from juno/github-flow.ja.md
GitHub Flow (Japanese translation)
@ayakix
ayakix / zsh_history_sort.py
Created October 11, 2012 11:50 — forked from nishio/git_stat.py
show active command on Zsh
from collections import Counter, defaultdict
import sys
try:
#FILENAME = "/Users/{hoge}/.zhistory"
FILENAME = sys.argv[1]
except:
print "USAGE: zsh_history_sort.py <your_history_file>"
sys.exit(1)
@wobbals
wobbals / AvcEncoder.java
Created October 31, 2012 22:46
MediaCodec encoder sample
package com.opentok.media.avc;
import java.io.IOException;
import java.nio.ByteBuffer;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
public class AvcEncoder {
@linjunpop
linjunpop / Capybara-Rspec-Rails-assets-pipeline.md
Last active August 14, 2021 05:42
Capybara, Rspec, Rails assets pipeline
@kylefox
kylefox / gist:4512777
Created January 11, 2013 18:15
If you want to use Xcode's FileMerge as your git mergetool, this is how you set it up.
# Tell system when Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff
@jessecurry
jessecurry / paperclip_migration.rake
Created August 13, 2013 21:51
Rake task for migrating paperclip attachments stored on S3 when you have to change your path.
namespace :paperclip_migration do
desc 'Migrate data'
task :migrate_s3 => :environment do
# Make sure that all of the models have been loaded so any attachments are registered
puts 'Loading models...'
Dir[Rails.root.join('app', 'models', '**/*')].each { |file| File.basename(file, '.rb').camelize.constantize }
# Iterate through all of the registered attachments
puts 'Migrating attachments...'