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
@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
@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

@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
@telent
telent / gist:9742059
Last active February 19, 2024 09:30
12 factor app configuration vs leaking environment variables
App configuration in environment variables: for and against
For (some of these as per the 12 factor principles)
1) they are are easy to change between deploys without changing any code
2) unlike config files, there is little chance of them being checked
into the code repo accidentally
3) unlike custom config files, or other config mechanisms such as Java
@edokeh
edokeh / index.js
Last active April 18, 2024 08:07
佛祖保佑,永无 BUG
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@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("輸入帳號...")
@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
@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
}
@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