Skip to content

Instantly share code, notes, and snippets.

View TexRx's full-sized avatar
🏠
Working from home

Bobbie Tables TexRx

🏠
Working from home
  • Austin, TX
View GitHub Profile
@TexRx
TexRx / gist:2772814
Created May 23, 2012 01:55 — forked from karlseguin/gist:2462535
extensions to HTMLDocument for setting up click and keypress events
//Helper extension for setting up document.on('click') and document.on('keypress') if escape...
//I think it's pretty stupid code, inspired by having eaten absolutely too much, watcha gonna do.
//usage:
// document.on('escape', hide);
// document.on('click', hide);
(function(){
var events = {'escape': [], 'click': [], 'enter': []};
@TexRx
TexRx / gist:2772817
Created May 23, 2012 01:56 — forked from karlseguin/gist:1876859
sublime text 2 script to save to remove server
#variation of http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ that adds creating new folders remotely.
import sublime_plugin, os
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
remote = { "/Users/leto/work/project": ["/usr/bin/scp", None, "user@server", "root_remote_path_like ~/project/", None] }
for dirname, target in remote.iteritems():
if view.file_name().startswith( dirname ):
@TexRx
TexRx / gist:2772820
Created May 23, 2012 01:56 — forked from karlseguin/gist:1694156
style override I use for duckduckgo.com
body{background:#fff;font-family:'Verdana';font-size:16px;}
#header{background-image:nome;background:#f0f0f0;border-bottom:1px solid #ddd;height:45px}
#header_logo, #keyboard_shortcuts{display:none !important;}
#search_form{border:none;margin-top:4px}
#search_form_input{border:solid #ccc;border-width:1px 0 1px 1px}
#search_form_input_clear{border:solid #ccc;border-width:1px 0}
#header_button_menu_wrapper{position:absolute;top:3px;right:20px;}
#header_button{background:none;border:none}
#header_button_menu_wrapper a.header_button_menu_item{color:#555;font-size:90%;text-shadow:none;background:none;text-transform: lowercase}
#zero_click_abstract, #zero_click_abstract_top, .results_zero_click, .results_zero_click_more{border:none;}
@TexRx
TexRx / gist:2772822
Created May 23, 2012 01:57 — forked from karlseguin/gist:1336377
C# pool creator
public class Pool<T>
{
private readonly int _count;
private readonly Queue<T> _pool;
private readonly Func<Pool<T>, T> _create;
private readonly object _lock = new object();
public Pool(int count, Func<Pool<T>, T> create)
{
_count = count;
@TexRx
TexRx / gist:2772825
Created May 23, 2012 01:58 — forked from karlseguin/gist:1327266
Nodejs and MongoDB, A Beginner’s Approach - Mirror

this is a mirror of http://blog.ksetyadi.com/2011/10/nodejs-and-mongodb-a-beginners-approach/

This is not a book and I didn’t try to sell a book to you.

The term “A Beginner’s Approach” reflects my self when finding a hard way out to connect Nodejs to MongoDB. There are lots of libraries available to use when connecting Nodejs to MongoDB. If you were trying to make your feet wet, and that’s what I’m doing until today, you probably want to try this approach. I can’t promise anything but at least, you will not get a headache.

First, read about Nodejs. After that, MongoDB. If you’re already familiar with it, skip it and install both on your system. There maybe vary depending on your system. If you use Mac and Homebrew (or MacPorts), you’re lucky. Just do this:

$ brew install node
// account.js
var Store = new (require('./store').Store)('accounts', {'_id': 'id', 's': 'secret'}, function(){return new Account();});
var Account = function Account() {
this.id = this.secret = null;
};
Account.findById = function(id, callback) {
Store.findOne({'_id': Store.idFromString(id)}, function(err, result) {
if (err) { callback(err); }
@TexRx
TexRx / gist:2772832
Created May 23, 2012 02:00 — forked from karlseguin/gist:852817
simulate typing into an input
function simType(input, value)
{
var characters = value.split('');
var i = 0;
var id = setInterval(function()
{
input.value += characters[i++];
if (i == characters.length) { clearInterval(id); }
}, 75);
};
@TexRx
TexRx / gist:2772841
Created May 23, 2012 02:04 — forked from karlseguin/gist:782799
try to bust through proxies for a remote address
private static readonly string[] _ipHeaderOrder = new[] { "HTTP_X_FORWARDED_FOR", "HTTP_X_CLUSTER_CLIENT_IP", "REMOTE_ADDR" };
public static string ClientAddress(this HttpRequest request)
{
foreach (string header in _ipHeaderOrder)
{
string ipAddress = request.ServerVariables[header];
if (ipAddress != null)
{
return ipAddress;
@TexRx
TexRx / iframe_test.html
Created August 29, 2012 02:02 — forked from rauschma/iframe_test.html
iframe test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>instanceof test</title>
<script>
// test() is called from the iframe
function test(obj) {
var iframeWin = frames[0];
console.log(obj instanceof Object); // false
@TexRx
TexRx / mq.css
Created October 4, 2012 03:39 — forked from chriscoyier/mq.css
@media only screen and (min-width: 320px) {
/* Small screen, non-retina */
}
@media
only screen and (-webkit-min-device-pixel-ratio: 2) and (min-width: 320px),
only screen and ( min--moz-device-pixel-ratio: 2) and (min-width: 320px),
only screen and ( -o-min-device-pixel-ratio: 2/1) and (min-width: 320px),