Skip to content

Instantly share code, notes, and snippets.

@chensoren
chensoren / auto_zoom_markers.js
Created July 5, 2013 09:53
Auto Zoom To Fit All Markers on Google Maps API v3
var LatLngList = new Array (new google.maps.LatLng (52.537,-2.061), new google.maps.LatLng (52.564,-2.017));
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds ();
// Go through each...
for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
// And increase the bounds to take this point
bounds.extend (LatLngList[i]);
}
// Fit these bounds to the map
map.fitBounds (bounds);
@chensoren
chensoren / sum_num_str.sh
Created July 11, 2013 02:43
计算字符串的数值总和
# need sum total number from following string with number
# [\"02:00\",233.39],[\"02:01\",233.32],[\"02:02\",233.31],[\"02:03\",233.3],[\"02:04\",233.29],[\"02:05\",233.26],[\"02:06\",233.3],[\"02:07\",233.32],[\"02:08\",233.3],[\"02:09\",233.4],[\"02:10\",233.38],[\"02:11\",233.31],[\"02:12\",233.34],[\"02:13\",233.35],[\"02:14\",233.32],[\"02:15\",233.43],[\"02:16\",233.44],[\"02:17\",0.0],[\"02:18\",0.0],[\"02:19\",233.56],[\"02:20\",233.58],[\"02:21\",233.45],[\"02:22\",233.4],[\"02:23\",233.56],[\"02:24\",233.6],[\"02:30\",233.57],[\"02:31\",233.53],[\"02:32\",233.7],[\"02:33\",233.71],[\"02:34\",233.63],[\"02:35\",233.67],[\"02:36\",233.61],[\"02:37\",233.68],[\"02:38\",233.69],[\"02:39\",233.62],[\"02:40\",233.53],[\"02:41\",233.6],[\"02:42\",233.7],[\"02:43\",233.73],[\"02:44\",233.76],[\"02:45\",233.72],[\"02:46\",233.72],[\"02:47\",233.7],[\"02:48\",233.65],[\"02:49\",233.65],[\"02:50\",233.68],[\"02:51\",233.72],[\"02:52\",233.72],[\"02:53\",233.74],[\"02:54\",233.68],[\"02:55\",233.73],[\"02:56\"
@chensoren
chensoren / dump_mongo.sh
Last active December 21, 2015 04:09
dump mongodb data
mongodump -h dbhost -u username -p -d dbname -o /tmp/data
#restore mongo data
mongorestore -h dbhost -d dbname --directoryperdb /tmp/data/dbname
@chensoren
chensoren / gem_version_require.rb
Last active December 22, 2015 23:29
require specify gem version
require 'rubygems'
begin
gem "mechanize", "2.7.0"
rescue Gem::LoadError => e
system("gem install mechanize -v=2.7.0")
Gem.clear_paths
end
begin
gem "activesupport", "3.2.12"
server {
listen 8080;
server_name example.dev www.example.dev;
location / {
root /Users/Cobby/Sites/Example;
if ($host = 'www.example.dev' ) {
rewrite ^/(.*)$ http://example.dev:8080/$1 permanent;
}
@chensoren
chensoren / magento_1.8_nginx.conf
Last active December 25, 2015 08:49
nginx configuration for magento 1.8
server {
listen 80;
server_name magento.local;
access_log /usr/local/opt/nginx/logs/magento.local.access.log main;
root /Users/eric/Sites/magento;
location / {
index index.php;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Host $host;
# original copyright from https://github.com/ruby-china/ruby-china/blob/master/app/models/mongoid/base_model.rb
# add simple support for conditional find batch
# usage: Model.find_in_batches({:cond => {} })
module Mongoid
module BaseModel
extend ActiveSupport::Concern
module ClassMethods
@chensoren
chensoren / node_redis_command.js
Created October 25, 2013 03:03
set connection name by node redis
//redis command: CLIENT SETNAME connection-name
subscriber.send_command('CLIENT', ['SETNAME', 'connection_name']);
@chensoren
chensoren / linux.md
Last active December 29, 2015 17:09
linux shell command collection
  • 通过ssh传输文件

    scp -rp /path/filename username@remoteIP:/path #将本地文件拷贝到服务器上# scp -rp username@remoteIP:/path/filename /path #将远程文件从服务器下载到本地# tar cvzf - /path/ | ssh username@remoteip "cd /some/path/; cat -> path.tar.gz" #压缩传输# tar cvzf - /path/ | ssh username@remoteip "cd /some/path/; tar xvzf -" #压缩传输一个目录并解压# rsync -avh /path/to/file/or/dir user@host:/path/to/dir/or/file rsync -avh user@host:/path/to/file/or/dir /path/to/file/or/dir

@chensoren
chensoren / block_config.rb
Created December 6, 2013 09:00
Block Configuration
class Configuration
attr_accessor :username, :password
def initialize
yield self
end
end
c = Configuration.new do |config|