Skip to content

Instantly share code, notes, and snippets.

View lulalala's full-sized avatar

lulalala lulalala

View GitHub Profile
@lulalala
lulalala / Controller Action.rb
Last active August 29, 2015 14:09
Payment Notification
# in OrdersController
def payment_notify
l = PaymentNotification.new
l.order_id = params[:id]
l.payment_method_id = params[:payment_method_id]
l.url = request.fullpath
l.raw_post = request.raw_post
l.data = {remote_ip:request.remote_ip}
@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
@lulalala
lulalala / calendar
Created September 3, 2014 06:13
SimpleCalendar styling
<table class="calendar"><thead><tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr></thead><tbody><tr><td class="day past current-month wday-1">09/01
</td><td class="day past current-month wday-2">09/02
</td><td class="day today current-month wday-3"><a href="">09/03</a>
</td><td class="day future current-month wday-4">09/04
</td><td class="day future current-month wday-5">09/05
</td><td class="day future current-month wday-6">09/06
</td><td class="day future current-month wday-0">09/07
</td></tr><tr><td class="day future current-month wday-1">09/08
</td><td class="day future current-month wday-2">09/09
</td><td class="day future current-month wday-3">09/10
@lulalala
lulalala / original.html
Created February 7, 2014 03:50
Nokogiri 1.5.11 wbr element parsing. As you can see the "text after" got removed in the parsed.html because there are too many nested wbr elements.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>1999</title>
</head>
<body>
<br><br><br>
text before
<p>
@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 / splat_benchmark.rb
Created October 16, 2013 08:48
Using splat to accept large array is slow.
require 'benchmark'
iterations = 100_000
def a(*args)
args.size
end
def b(args)
args.size
@lulalala
lulalala / hash key benchmark
Created October 14, 2013 08:42
Use object_id as hash key can be 20x faster
ary= []
30.times do |i|
ary << {a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8}
end
Benchmark.bmbm do |x|
x.report("hash as key") do
hash = {}
ary.each do|a| hash[a] = 1 end
@lulalala
lulalala / 中華民國地理極點經緯值
Created September 11, 2013 06:48
中華民國地理極點經緯值,可用來辨別一個經緯度是否在範圍內。
最北 西引島北固礁
26.38306, 120.47611
最南 七星岩
21.758883, 120.824706
最東 赤尾嶼
25.921667, 124.558333
最西 金門縣烈嶼鄉
@lulalala
lulalala / logdown
Last active December 21, 2015 22:09
grammar correction
Hey, fellow hackers!
This week we are bringing "Custom Theme" to you !
1. Starting today, we now support custom themes. You can customize your own template by going to Theme's setting :
http://logdown.com/account/blogs/lulalala/themes
* See announcement here: New Feature: Custom Theme
@lulalala
lulalala / yahoo_api_example.json
Created August 15, 2013 07:41
Tiger der Yahoo BUY API
{"categories"=>{"count"=>"0"}}
{"categories"=>{"category"=>{"no"=>"76044", "level_no"=>"4", "name"=>"NANING9", "type"=>"區"}, "count"=>"1"}}
{"categories"=>{"category"=>[{"no"=>"17746", "level_no"=>"4", "name"=>"Fashion Focus", "type"=>"區"}, {"no"=>"14482", "level_no"=>"4", "name"=>"MM25下身系列", "type"=>"區"}], "count"=>"2"}}