Skip to content

Instantly share code, notes, and snippets.

View tonytonyjan's full-sized avatar
🪲
Making bugs

簡煒航 (Weihang Jian) tonytonyjan

🪲
Making bugs
View GitHub Profile
@yuki24
yuki24 / after.md
Last active August 29, 2015 14:19
Improving Jaro-Winkler

Total allocated 240

Total retained 0

allocated memory by gem

 48000  did_you_mean/lib

allocated memory by file

48000 /GitHub/did_you_mean/lib/did_you_mean/jaro_winkler.rb

@NARKOZ
NARKOZ / gist:4294977
Last active October 26, 2015 06:48
ImageMagick vs GraphicsMagick (Resizing to Fill a Given Space)
# gem 'mini_magick' 5217dfe
# GraphicsMagick 1.3.17
# ImageMagick 6.7.0-10
# Resize to fill (old method)
# http://www.imagemagick.org/Usage/resize/#space_fill
#
# works with ImageMagick as expected
# fails to work with GraphicsMagick as expected
@advancedor96
advancedor96 / loginPTT
Created November 20, 2013 18:21
自動登入PTT後,再自動登出的程式。
import telnetlib
import sys
import Account #My file. It contains Account.id, Account.password
import time
tn = telnetlib.Telnet('ptt.cc')
time.sleep(1)
content = tn.read_very_eager().decode('big5','ignore')
print("首頁顯示...")
if "請輸入代號" in content:
print("輸入帳號...")
@preallocate = []
500_000.times do
@preallocate << ""
end
def process_request
allocate = rand(80_000) + 20000
req = []
@madwork
madwork / decode_session_cookie.rb
Last active October 22, 2020 18:13 — forked from profh/decode_session_cookie.rb
Rails 4.1+ Decode Session
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@jandudulski
jandudulski / auth.rb
Last active September 14, 2022 12:09
CSRF on Grape
# based on http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
module Auth
extend ActiveSupport::Concern
included do
helpers do
def session
env['rack.session']
end
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@lonnen
lonnen / gist:3101795
Created July 12, 2012 23:24
git grep and git blame. two great tastes that taste great together
# from i8ramin - http://getintothis.com/blog/2012/04/02/git-grep-and-blame-bash-function/
# runs git grep on a pattern, and then uses git blame to who did it
ggb() {
git grep -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
# small modification for git egrep bash
geb() {
git grep -E -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
@edokeh
edokeh / index.js
Last active May 7, 2024 12:31
佛祖保佑,永无 BUG
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \