Skip to content

Instantly share code, notes, and snippets.

View shockby's full-sized avatar

Takeshi Ohashi shockby

View GitHub Profile
@shockby
shockby / db_fixtures_dump.rake
Created September 4, 2020 10:04 — forked from ecleel/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
@shockby
shockby / db_fixtures_dump.rake
Created September 4, 2020 10:04 — forked from ecleel/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
@shockby
shockby / rspec_rails_cheetsheet.rb
Created August 10, 2018 06:42 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
module FactoryBot
module Syntax
module Methods
def find_or_create(name, *attributes, &block)
attributes = FactoryBot.attributes_for(name, *attributes)
klass = FactoryBot.factory_by_name(name).build_class
enums = klass.defined_enums
find_attributes = attributes.clone
find_attributes.keys.each do |key|
find_attributes[key] = enums[key.to_s][find_attributes[key]] if enums.has_key?(key.to_s)
@shockby
shockby / 0_reuse_code.js
Created July 14, 2017 01:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shockby
shockby / google_geocode.rb
Created November 11, 2016 02:24 — forked from komasaru/google_geocode.rb
Ruby script to get a address or latitude, longitude with Google Geocoding API.
#*********************************************
# 住所から緯度・経度を取得する、又は、
# 緯度・経度から住所を取得する。
# ( by Google Geocode API )
#*********************************************
#
require 'json'
require 'net/http'
BASE_URL = "http://maps.googleapis.com/maps/api/geocode/json"
@shockby
shockby / s3.sh
Last active June 27, 2017 21:23 — forked from chrismdp/s3.sh
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
file=$2