Skip to content

Instantly share code, notes, and snippets.

Testing behavior of a CollectionProxy based on :dependent option, delete method used and assocation type (:has_many vs :has_many :through)

:has_many association

class Category < ActiveRecord::Base
	has_many :contacts, through: :categorizations
	has_many :categorizations, dependent: DEPENDENT
end
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which
* uses OkHttp as its transport.
*/
@y-yagi
y-yagi / gist:cec784b99b56a226e60d
Created November 9, 2014 06:40
TracePoint study
require 'minitest'
require "minitest/autorun"
require 'power_p'
require 'ripper'
trace = TracePoint.new(:raise) do |tp|
if tp.raised_exception.class == Minitest::Assertion
file, lineno = tp.raised_exception.location.split(':')
line = open(file).each_line.drop(lineno.to_i - 1).first
idents = Ripper.sexp(line)
# todos_controller.rb
class TodosController < ApplicationController
respond_to :html, :json, :xml
end
# application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
rescue_from ActionView::MissingTemplate, with: :check_respond_error
@y-yagi
y-yagi / gist:6962c53da74355226e7c
Last active August 29, 2015 14:10
warnメッセージを出力している箇所を調べる
trace = TracePoint.new(:c_call) do |tp|
if tp.method_id == :warn
print tp.binding.eval('caller_locations').join("\n")
end
end
trace.enable
@y-yagi
y-yagi / gist:b0504a365625295d6d97
Created December 6, 2014 05:55
minitest-sound test script
require 'minitest/autorun'
require 'minitest/sound'
Minitest::Sound.success = '/home/yaginuma/Dropbox/tmp/music/other/sey.mp3'
Minitest::Sound.failure = '/home/yaginuma/Dropbox/tmp/music/other/mdai.mp3'
Minitest::Sound.during_test = '/home/yaginuma/Dropbox/tmp/music/other/rs1_25_beatthemup.mp3'
class A
def b
sleep 5
@y-yagi
y-yagi / gist:d71c88ca407cc09f28e4
Created December 14, 2014 03:30
pg array parser 性能測定
require 'benchmark'
require 'benchmark/ips'
require 'ruby-prof'
require 'pg_array_parser'
require 'active_record/connection_adapters/postgresql/array_parser'
class MyPgArrayParser
include PgArrayParser
end
@y-yagi
y-yagi / gist:990abd6e084d02f8504f
Created December 29, 2014 22:45
OpenCV install script
# see: https://help.ubuntu.com/community/OpenCV
version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9]+)+' | cut -c2-)"
echo "Installing OpenCV" $version
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -qq remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg
echo "Downloading OpenCV" $version
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick-6.8.7-7.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
#!/usr/bin/env ruby
BIT_OR = '\|'
BIT_AND = '\&'
ADD = '\+'
MULTIPLATION = '\*'
input = ARGV[0]
[BIT_OR, BIT_AND, ADD, MULTIPLATION].each do |operator|