Skip to content

Instantly share code, notes, and snippets.

View southwolf's full-sized avatar

SouthWolf southwolf

  • HSBC
  • Guangzhou, China
View GitHub Profile
@southwolf
southwolf / gist:c8974c14d84f565caa52
Last active August 29, 2015 14:03
SDL Event Processing
while (!done)
{
if (SDL_WaitEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
view.interrupt();
decode.interrupt();
done = 1;

Routes

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

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

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

# routes.rb
@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"
@southwolf
southwolf / font2pbm.rb
Created March 29, 2013 09:49
Pebble font resource to pbm(the most close format I can think of to the pebble res) converter **Faulty**
class Image
attr_accessor :width, :height, :bitmap
end
img = Image.new
hexmap = nil
File.open('font1', 'rb') do |f|
data = f.read
img.width = data[0].ord
# 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):
@southwolf
southwolf / manifest.json
Last active December 15, 2015 15:09
Correct Resource Map of Pebble v1.9.1
{
"debug": {
"resourceMap": {
"friendlyVersion": "v1.8-HM",
"media": [
{
"defName": "PUG",
"file": "images/pug.png",
"type": "png"
},
# 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):
$ ./waf configure
Waf: The wscript in 'c:\\Users\\SouthWolf\\pebble\\sdk\\watches\\segment_six' is
unreadable
Traceback (most recent call last):
File "c:\Users\SouthWolf\pebble\sdk\watches\segment_six\waf-1.7.0-9334f7e963be
e5410f4fa28728feffdd\waflib\Scripting.py", line 87, in waf_entry_point
set_main_module(Context.run_dir+os.sep+Context.WSCRIPT_FILE)
File "c:\Users\SouthWolf\pebble\sdk\watches\segment_six\waf-1.7.0-9334f7e963be
e5410f4fa28728feffdd\waflib\Scripting.py", line 112, in set_main_module
Context.g_module=Context.load_module(file_path)
#include <string.h>
#include <ctype.h>
const uint8_t req[5] = {0x00, 0x01, 0x00, 0x11, 0x00};
const uint8_t cap[17] = {0x00, 0x0d, 0x00, 0x11, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32};
const uint8_t ping[9] = {0x00, 0x05, 0x07, 0xd1, 0x00, 0xde, 0xad, 0xbe, 0xef};
const uint8_t sms[23] = {0x00, 0x13, 0x0b, 0xb8, 0x01, 0x01, 0x41, 0x01, 0x42, 0x0d, 0x31, 0x33, 0x37, 0x36, 0x34, 0x36, 0x36, 0x36, 0x35, 0x39, 0x30, 0x30, 0x30};
//uint8_t serialMessage[200];
int index = 0;