Skip to content

Instantly share code, notes, and snippets.

View realguess's full-sized avatar

Chao Huang realguess

View GitHub Profile
var biggestHeight = "0";
// Loop through elements children to find & set the biggest height
$(".container *").each(function(){
// If this elements height is bigger than the biggestHeight
if ($(this).height() > biggestHeight ) {
// Set the biggestHeight to this Height
biggestHeight = $(this).height();
}
});
$(document).height()
@realguess
realguess / aa
Created January 30, 2016 13:04
aa
aa
date
@realguess
realguess / aws-security-group
Last active January 3, 2016 11:29
Authorize or revoke the public IP address of the current machine on all AWS security groups.
#!/usr/bin/env bash
#
# Authorize or revoke the public IP address of the current machine on all AWS
# security groups.
#
# Usage:
#
# # Authorize TCP port 22 access on all security groups:
# aws-security-group authorize 22 us-east-1
#
@realguess
realguess / days_passed.js
Created September 11, 2013 19:39
Get the number of days since the beginning of the year.
// Days Passed Since New Year
// ==========================
//
// (c) 2013 Chao Huang <chao@realguess.net>
// Quick Example
// -------------
function days() {
return (new Date(new Date().toISOString().substr(0,10)).getTime() - new Date('' + new Date().getFullYear()).getTime()) / (1000 * (60 * 60 * 24));
}
@realguess
realguess / http_method.js
Created May 8, 2013 16:20
Node server displaying HTTP method
// Node server displaying HTTP method
// ==================================
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(req.method + '\n');
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');
/**
* Add CORS support.
*/
app.all('*', function (req, res, next) {
if (!req.get('Origin')) {
return next();
}
// use "*" here to accept any origin
res.set('Access-Control-Allow-Origin', '*');
@realguess
realguess / dbconn.js
Created January 12, 2012 05:49
How to close all connections to MongoDB server
var mongodb = require('mongodb')
, server = new mongodb.Server('localhost', 27017, {})
, db = new mongodb.Db('test', server, {})
;
console.log('[1]', db.serverConfig._serverState);
db.open(function (err, db) {
console.log('[2]', err, db.serverConfig._serverState);
db.close();
console.log('[3]', err, db.serverConfig._serverState);
@realguess
realguess / amazon-s3-starter.js
Created March 10, 2015 09:42
A starter template for using Amazon S3 with Amazon SDK.
// Put message to S3.
var aws = require('aws-sdk');
aws.config.update({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'us-east-1'
});
var s3 = new aws.S3();