Skip to content

Instantly share code, notes, and snippets.

View tfanme's full-sized avatar
🎯
Focusing

tfan tfanme

🎯
Focusing
View GitHub Profile
@tfanme
tfanme / sqlserver2mongo.rb
Created March 22, 2013 04:34
export data from SQL Server to MongoDB using Ruby and Rails
require "rubygems"
require "active_record"
require "mongo"
include Mongo
# 声明一个 MongoDB client
@client = MongoClient.new('localhost', 27017)
# MongoDB db
@db = @client['your_mongo_dbname']
# 首先安装 Rails 连接 SQL Server 所需要的驱动
gem update --system
gem install activerecord-sqlserver-adapter
#再安装 10gen 提供的 MongoDB 驱动:
gem install mongo
# 这一步会自动安装 bson,再安装 bson_ext
gem install bson_ext
@tfanme
tfanme / whichAndCrontab.sh
Created March 22, 2013 07:31
Use Crontab command to start forever for Node.js on bootstarp
/usr/bin/mongod
# which forever
/usr/local/bin/forever
# which python
/usr/local/bin/python
# which python2
/usr/local/bin/python2
# which python3
/usr/local/bin/python3
# which httpd
@tfanme
tfanme / vhost.conf
Created March 25, 2013 07:44
Apache proxy mode virtual host configuration
<VirtualHost *:80>
ServerAdmin admin@gmail.com
ServerName foobar.com
ServerAlias www.foobar.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
@tfanme
tfanme / httpd.conf
Created March 25, 2013 07:50
Apache proxy module
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
@tfanme
tfanme / install-activerecord-sqlserver-adapter-under-centos.sh
Created March 28, 2013 06:31
Install activerecord-sqlserver-adapter under CentOS
# Use /download as our temporary download directory
# Start download and install freetds
cd /download
# Offical Site: freetds.org
wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
tar zxvf freetds-0.91
cd freetds-0.91
./configure
make
make install
@tfanme
tfanme / xmlBodyParser.js
Created March 31, 2013 14:49
using xml2js to enable request body parsing for express
var express = require('express'),
var app = express();
var utils = require('express/node_modules/connect/lib/utils'), xml2js = require('xml2js');
function xmlBodyParser(req, res, next) {
if (req._body) return next();
req.body = req.body || {};
@tfanme
tfanme / mongodb_nodejs_signup.js
Last active December 17, 2015 22:29
MongoDB Query 对象中 $or 的使用,判断 username 或 email 是否存在。
var userSignup = function (req, res) {
var signup = req.body;
// 用户对象
var muuser = {
"username": signup.username,
"password": signup.password,
"firsttime": (new Date()).getTime(),
"email": signup.email
};
@tfanme
tfanme / contacts.js
Created July 20, 2013 23:40
PhoneGap 3.x Contacts API Example
/* Translation of property type labels contact API ---> iPhone
*
* phone: work, home, other, mobile, fax, pager -->
* kABWorkLabel, kABHomeLabel, kABOtherLabel, kABPersonPhoneMobileLabel, kABPersonHomeFAXLabel || kABPersonHomeFAXLabel, kABPersonPhonePagerLabel
* emails: work, home, other ---> kABWorkLabel, kABHomeLabel, kABOtherLabel
* ims: aim, gtalk, icq, xmpp, msn, skype, qq, yahoo --> kABPersonInstantMessageService + (AIM, ICG, MSN, Yahoo). No support for gtalk, xmpp, skype, qq
* addresses: work, home, other --> kABWorkLabel, kABHomeLabel, kABOtherLabel
*
*
*/
@tfanme
tfanme / typeof.js
Last active December 25, 2015 03:59
JavaScript:typeof
// sample1:get the type of variables
var str = 'this is a test.';
alert(typeof str);
// or
// alert(typeof(str));
// sample2: get the type of literals
alert(typeof 'test!');