Skip to content

Instantly share code, notes, and snippets.

View lulalala's full-sized avatar

lulalala lulalala

View GitHub Profile
@lulalala
lulalala / reset_change_bug
Created August 16, 2012 07:34
Need to reset change twice for it to be marked unchanged
>> t = Topic.find(47083); time = t.event.end
Topic Load (9.2ms) SELECT `topics`.* FROM `topics` WHERE `topics`.`id` = 47083 LIMIT 1
Topic::Event Load (0.5ms) SELECT `periods`.* FROM `periods` WHERE `periods`.`type` IN ('Topic::Event') AND `periods`.`owner_id` = 47083 AND `periods`.`owner_type` = 'Topic' LIMIT 1
=> Thu, 16 Aug 2012 09:00:04 CST +08:00
>> t.event.changed?
=> false
>> t.event.end = time + 1.second
=> Thu, 16 Aug 2012 09:00:05 CST +08:00
>> t.event.end_changed?
=> true
@lulalala
lulalala / URI param parsing
Created August 14, 2012 06:56
How to append a parameter into the url in Ruby?
u = URI.parse("http://example.com/user/1234?a=1&b=2")
# <URI::HTTP:0x007fe3d9a1f238 URL:http://example.com/user/1234?a=1&b=2>
query = u.query #"a=1&b=2"
query = query << "&c=3"
u.path #"/user/1234"
u.to_s #"http://example.com/user/1234?a=1&b=2"
u.merge(query).to_s #"http://example.com/user/a=1&b=2&c=3" WHY DOES 1234 disappear?!
# I want to get http://example.com/user/1234?a=1&b=2&c=3"
@lulalala
lulalala / image_folder_partition
Created August 10, 2012 10:12
Partitions numeric folders into 3 hierarchy
# Place under the same folder where the many folders exists, then run the script.
# This will convert folders like 12345678\ to 012\345\678\
require 'fileutils'
Dir.glob("*") do |f|
if not FileTest.directory?(f)
next
end
@lulalala
lulalala / nginx.conf
Created August 3, 2012 08:01
For http://serverfault.com/questions/405264/ ,having problem using try_files
worker_processes 20;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
@lulalala
lulalala / gist:3214537
Created July 31, 2012 07:38
rest-more facebook error
client = RestCore::Facebook.new(app_id: FACEBOOK_APP_ID, secret: FACEBOOK_APP_SECRET)
client.post("1234567/feed", params: post_params)
# error:
# RestCore::Facebook::Error::InvalidAccessToken: {"error"=>{"message"=>"(#200) This API call requires a valid app_id.", "type"=>"OAuthException", "code"=>200}} from https://graph.facebook.com/1234567/feed
@lulalala
lulalala / BorderboxModelHolyGrailLayout.html
Created July 6, 2011 03:33
Simplication of The Holy Grail of Layouts using Border-box model
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The Holy Grail of Layouts: Example #1: A List Apart (Using Border-box model)</title>
<style type="text/css">
body {
min-width: 550px; /* prevent narrow window from breaking layout */
}
div {
<剩下><集數><ComicMarket><屬性><語言>
delete [comic] [Comic] [漫畫] [漫画] * (\(?同人誌\)?) 同人誌 [同人] [日文] (同人CG集)
delete [H-COMIC] [同人] [日文] (同人CG集) * (?i)\[[h][-_\s]?comic\] * (?i)\[h漫\]
delete (一般コミック) (成年コミック) (成年コミック・雑誌) (成年コミック.雑誌) (エロ)
delete [PNG]
delete * \[全.冊\] * \(全\d*集\)
delete * \[\d*p\]
delete (同人誌)
replace <語言> [中] [C] (中文) * (\[中.\]) (繁體) [BIG5] [日翻中] @最果ての神狐漢化 * @?悠月工房 * \[[^\]]*?漢化[^\]]*?\] * \[?中文[化版]?\]? * [\(\[]?漢化[\]\)]? [大山文化]
replace <語言> [英] (英) [ENG] [FAKKU] (English)