This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxSetup({ | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Struct to Hash: | |
class Struct | |
def to_hash | |
Hash[*members.zip(values).flatten] | |
end | |
end | |
Hash to Struct: | |
class Hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder