Skip to content

Instantly share code, notes, and snippets.

View southwolf's full-sized avatar

SouthWolf southwolf

  • Amplifyhealth
  • Hong Kong
View GitHub Profile
@southwolf
southwolf / stats.js
Created January 21, 2019 03:14 — forked from izaac/stats.js
An example statistics library in Javascript.
#!/usr/bin/env node
/* jshint node: true */
'use strict';
var program = require('commander');
function add(a, b){
return a + b;
}
function numericSort(a,b) {
@southwolf
southwolf / main.go
Created May 7, 2018 14:45 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@southwolf
southwolf / eventmachine.rb
Created September 16, 2017 14:21 — forked from marianposaceanu/eventmachine.rb
Initializer that allows EventMachine to run within Rails, and work with AMQP, Passenger, Thin and Capybara
require 'amqp'
module HiringThingEM
def self.start
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
# for passenger, we need to avoid orphaned threads
if forked && EM.reactor_running?
EM.stop
end
Thread.new {
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"

近来由于 Mac 出了点小问题一直没有解决,加上用了已经有好长一段时间,一直想清理一下(精神洁癖作祟),所幸重装了事。没有使用 TimeMachine,所以需要先行将一些觉得尚有价值的文件拷贝下来。

写下这篇文章,也是为了以后再次遇到问题能够有章可循,不至于胡乱一通重装。本文也会持续更新,欢迎大家分享更好的使用技巧与经验。

重装 macOS

在线恢复系统实在太慢,进行在 Windows 下制作 Mac U盘启动盘重装系统. 额外所需的物理设备为 U 盘一个,8G 及以上为宜。

1. 准备软件与镜像

@southwolf
southwolf / tumblr-photo-ripper.rb
Created November 2, 2015 02:50 — forked from jamiew/tumblr-photo-ripper.rb
Download all the images from a Tumblr blog
# Usage:
# [sudo] gem install mechanize
# ruby tumblr-photo-ripper.rb
require 'rubygems'
require 'mechanize'
# Your Tumblr subdomain, e.g. "jamiew" for "jamiew.tumblr.com"
site = "doctorwho"

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
# coding=utf-8
import Image, ImageDraw, ImageFont
import struct
font_width = 16
font = ImageFont.truetype("/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", font_width)
def get_font_data(char):