Skip to content

Instantly share code, notes, and snippets.

View xifengzhu's full-sized avatar

leif Yi xifengzhu

View GitHub Profile
@xifengzhu
xifengzhu / qqwry.rb
Last active December 25, 2015 16:19
qqwry
# encoding : utf-8
require 'iconv'
module IPSearchAsk
class IpSearch
def initialize(file='public/IP_database/qqwry.dat')
filename = file
@file = File.open(filename,"r")
@index_first,@index_last = @file.read(8).unpack('L2')
@index_total = (@index_last - @index_first)/7 + 1
@xifengzhu
xifengzhu / ipsearch.rb
Created October 17, 2013 10:02
过百度api定位ip位置
# encoding : utf-8
require 'net/http'
require 'json'
module IPSearch
def self.ip_query(client_ip)
params = {}
params["ak"] = "9ea9********3800845b2753fa6" #百度的key
params["ip"] = client_ip
uri = URI.parse("http://api.map.baidu.com/location/ip?")
@xifengzhu
xifengzhu / Struct.rb
Last active August 29, 2015 14:00
Hash <=> Strut
Struct to Hash:
class Struct
def to_hash
Hash[*members.zip(values).flatten]
end
end
Hash to Struct:
class Hash
desc "API Routes"
task :routes do
Project::API.routes.each do |api|
method = api.route_method.ljust(10)
path = api.route_path
puts " #{method} #{path}"
end
end
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
}
});
//prefixer
@mixin prefixer ($property, $value, $prefixes) {
@each $prefix in $prefixes {
@if $prefix == webkit and $prefix-for-webkit == true {
-webkit-#{$property}: $value;
}
@else if $prefix == moz and $prefix-for-mozilla == true {
-moz-#{$property}: $value;
}
# get ordinal
# example: 1 -> 1st, 2 -> 2nd, 3 -> 3rd, 4 -> 4th
var getOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
<form name="form5" id="form5" method="post" action="#">
<input type="file" name="file5" id="file5" multiple onchange="preview5()"/>
</form>
<script type="text/javascript">
function getFileURL(file){
if (window.navigator.userAgent.indexOf("Chrome") >= 1 || window.navigator.userAgent.indexOf("Safari") >= 1) {
return window.webkitURL.createObjectURL(file);
}else {
return window.URL.createObjectURL(file);
}
# ~/.bash_profile
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
auto_set_tab_chrome_background_color;
}
function auto_set_tab_chrome_background_color {
# coding: utf-8
require 'active_support/callbacks'
class Record
include ActiveSupport::Callbacks
define_callbacks :save
# define_callbacks :kill
def save