Skip to content

Instantly share code, notes, and snippets.

@blessdyb
blessdyb / Dockerfile1
Created October 21, 2021 06:53 — forked from xeoncross/Dockerfile1
Examples of using multi-stage builds with docker and Go to reduce the final image size / attack surface.
# Sample from @citizen428 https://dev.to/citizen428/comment/6cmh
FROM golang:alpine as build
RUN apk add --no-cache ca-certificates
WORKDIR /build
ADD . .
RUN CGO_ENABLED=0 GOOS=linux \
go build -ldflags '-extldflags "-static"' -o app
FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
@blessdyb
blessdyb / the-rafpolyfill.js
Created February 16, 2021 05:49 — forked from getify/the-rafpolyfill.js
setTimeout vs. nested-RAF
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
@blessdyb
blessdyb / gist:1305740
Created October 22, 2011 07:22 — forked from Psli/gist:938931
Ruby / Rails Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@blessdyb
blessdyb / encode2gb2312.js
Created October 5, 2011 02:35 — forked from lemonhall/encode2gb2312.js
非常特殊的GB2312/GBK 的URIencode函数
function encodeToGb2312(str){
var strOut="";
for(var i = 0; i < str.length; i++){
var c = str.charAt(i);
var code = str.charCodeAt(i);
if(c==" ") strOut +="+";
else if(code >= 19968 && code <= 40869){
index = code - 19968;
strOut += "%" + z.substr(index*4,2) + "%" + z.substr(index*4+2,2);
}