Skip to content

Instantly share code, notes, and snippets.

View lulalala's full-sized avatar

lulalala lulalala

View GitHub Profile
@lulalala
lulalala / ffmpeg_compile.sh
Created October 17, 2013 16:33
compile options for minial ffmpeg which can encode/decode from images to h264
# for x264
./configure --enable-static \
--disable-opencl \
--disable-avs \
--disable-cli \
--disable-ffms \
--disable-gpac \
--disable-lavf \
--disable-swscale \
--prefix=/usr/local/
@lulalala
lulalala / friendly_inspect.rb
Created August 31, 2021 13:26
friendly inspect which omits long strings or complex objects
def inspect
result = instance_variables.each
.with_object({}) { |name, h| h[name] = instance_variable_get(name) }
.reject { |name, value| value.nil? }
.map { |name, value|
case value
when true, false, Symbol, Numeric, Array, Hash
"#{name}=#{value.inspect}"
when String
if value.length > 80
@lulalala
lulalala / banner.rb
Last active January 14, 2019 12:58 — forked from matheusvetor/banner.rb
Carrierwave image model validation on image dimensions/height/width.
class Banner < ActiveRecord::Base
attr_accessor :image_width, :image_height
mount_uploader :image, ImageUploader
validate :check_dimensions, :on => :create
def check_dimensions
if !image_cache.nil? && (image.width < 300 || image.height < 300)
errors.add :image, "Dimension too small."
end
end
@lulalala
lulalala / rspecgrep.sh
Created November 2, 2012 09:36
rspec with grep to run selected specs
function rspecgrep()
{
SPK_FILES=`find spec -type f -name "*_spec.rb" | grep $1`
echo $SPK_FILES
time rspec $SPK_FILES --format documentation
}
@lulalala
lulalala / personal_log.md
Created August 5, 2018 15:12
企劃 personal log

前言

軟體工程師都很能理解營運一個網站,完善的 log 系統是不可或缺的。 除了在發生錯誤時能用來除錯以外,也能透過資料分析來當作各項指標, 進行科學的自我改善。

同樣的,一個人生活中,紀錄不也有同樣的好處嗎? 有了紀錄,可以查詢到上次感冒是什麼時候, 新的習慣養成是否成功,生活上有什麼大小改變等等。

@lulalala
lulalala / rails_rollback_dirty_bug.rb
Last active January 22, 2018 08:45
Rails rollback does not revert to previous dirty state bug
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
@lulalala
lulalala / abstract.md
Last active January 15, 2018 16:32
abstract for RailsConf

There are many use cases where the ActiveModel::Errors interface is tedious to use, such message formatting and testing. This talk presents these cases, and explains why the limitation can be simply solved by taking an object-oriented approach, which results in the AdequateErrors gem. The gem's implementation is explained, and the talk will showcase examples on how it can make your coding life easier.

@lulalala
lulalala / gist:6be104641bcb60f9d0e8
Created November 11, 2014 09:30
RedirectResolver
require 'uri'
require 'net/http'
class RedirectResolver
def self.resolve(uri)
uri_input = uri
if uri.is_a? String
uri = URI.parse(uri)
end
foo.with_lock do
# insert a
bar.with_lock do
# Mysql2::Error: Lock wait timeout exceeded
end
end
@lulalala
lulalala / gist:db650baca4a5690467894f3cf742a33b
Created February 23, 2017 03:03
140 characters string, which Twitter think is 18 characters too long
12345678902234567890323456789042345678905234567890623456789072345678908234567890923456789002345678901234567890223456789032345678904234 t.now