Skip to content

Instantly share code, notes, and snippets.

View wxianfeng's full-sized avatar
🎯
Focusing

xianfeng wang wxianfeng

🎯
Focusing
  • HangZhou, China
View GitHub Profile
@kreeger
kreeger / surrogate.rb
Last active September 5, 2021 08:18
Converts a number into a UTF16 surrogate pair.
#!/usr/bin/env ruby
require 'fileutils'
require 'debugger'
class Fixnum
def to_surrogate_pair
if self >= 0x10000 && self <= 0x10FFFF
high = ((self - 0x10000) / 0x400).floor + 0xD800
low = ((self - 0x10000) % 0x400) + 0xDC00
@vincenting
vincenting / client.py
Last active February 5, 2021 06:42
微信公共平台脚本
# coding=utf-8
__author__ = 'Vincent Ting'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Vincent Ting'
import cookielib
import urllib2
@nightire
nightire / Changes in Rails 4_1.md
Last active September 28, 2025 09:55
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

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

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

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

# routes.rb
@nbibler
nbibler / gist:5307941
Last active August 26, 2024 20:44
A .powrc file which works with RVM's .rvmrc or .ruby-version (+ .ruby-gemset) configuration files.
if [ -f "$rvm_path/scripts/rvm" ]; then
source "$rvm_path/scripts/rvm"
if [ -f ".rvmrc" ]; then
source ".rvmrc"
fi
if [ -f ".ruby-version" ]; then
rvm use `cat .ruby-version`
fi
@hydra35
hydra35 / nginx.conf
Last active May 14, 2021 03:51
to gray, for Ya'An, Si Chuan earthquake
# 1. Make sure you have nginx sub module compiled in
# nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module'
# 2. add two directives below at HTTP level
# nginx.conf
http {
# ......
sub_filter '</head>' '<style type="text/css">html{ filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
@pjb3
pjb3 / irb_output.txt
Created October 1, 2013 00:21
Rails 4 appears to log SQL queries in the console in development by default. If it doesn't, I can't figure out why it is for me.
$ cat ~/.irbrc
cat: /Users/pbarry/.irbrc: No such file or directory
$ rails c
Loading development environment (Rails 4.0.0)
irb(main):001:0> Subscription.first
Subscription Load (2.5ms) SELECT "subscriptions".* FROM "subscriptions" ORDER BY "subscriptions"."id" ASC LIMIT 1
=> nil
irb(main):002:0> puts ENV.keys.sort
Apple_PubSub_Socket_Render
Apple_Ubiquity_Message
@xiangst0816
xiangst0816 / imgCenter.html
Last active June 3, 2018 08:51
将不同大小的img放在固定大小的div中; 要求img不能被拉伸覆盖、要水平居中放置在中间; 如果图片高度超出容器,则以高度为基准确定宽度,反之亦然; img不固定大小设置为inline,外层用line-height和text-align:center确定水平垂直居中;
<a href="">
<div class="cbCoorBox_e">
<img src="img/index/hanya.png" alt="合作机构">
</div>
</a>
@maraoz
maraoz / gist:388eddec39d60c6d52d4
Created February 20, 2016 22:03
Imagenet output tensor index to label mapping
{
0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
@fchollet
fchollet / classifier_from_little_data_script_1.py
Last active February 26, 2025 01:37
Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats
@AshikNesin
AshikNesin / react-file-upload.js
Created February 2, 2017 06:46
Simple React File Upload
import React from 'react'
import axios, { post } from 'axios';
class SimpleReactFileUpload extends React.Component {
constructor(props) {
super(props);
this.state ={
file:null
}