Skip to content

Instantly share code, notes, and snippets.

var EventsEmitter = require('events').EventEmitter;
pg.connect(..., function(err, client, done) {
var pageSize = 50;
var emitter = new EventsEmitter();
emitter.on('next', function(offset) {
callHandlersPaginated(offset);
});
emitter.on('end', function() {
// same as previous gist, but now via 'async' library
var async = require('async');
// some dummy rows
var rows = [];
for (var i = 0; i < 10000; i++) {
rows.push("this is row " + i);
}
// some dummy rows
var rows = [];
for (var i = 0; i < 10000; i++) {
rows.push("this is row " + i);
}
var index = 0;
var currentlyRunning = 0, maxRunning = 200;
function callHandler(row, cb) {
function floor(i, n) {
var r = i % n;
return i - r;
};
function floorToHours(date, nHours) {
var hourInMillis = 1000 * 60 * 60;
var dateInMillis = date.valueOf();
return new Date(floor(dateInMillis, nHours * hourInMillis));
};
@Chris927
Chris927 / why.js
Created July 2, 2014 07:13
Nice Little Javascript Scope Challenge
// credit: http://rzrsharp.net/2011/06/27/what-does-coffeescripts-do-do.html
var closures = [];
function createClosures() {
for (var i = 0; i < 5; i++) {
closures[i] = function() {
console.log("i=" + i);
}
}
}
@Chris927
Chris927 / copyable_attributes.rb
Created March 17, 2013 15:30
Failed attempt to implement generic 'deep copy' for AR... I'm just keeping it to document the thought process and the dead end I've reached.
module CopyableAttributes
def self.included(base)
def copyable_attributes_keys2
attributes.keys - self.class.protected_attributes.to_a - [ "created_at", "updated_at"] - foreign_key_list
# TODO: we also need to remove foreign keys... maybe have class method 'uncopyable_attributes_keys'?
end
private
def relevant_base_class
@Chris927
Chris927 / auntie.js
Created June 12, 2012 10:53
fun exercise around aunt Lily and her cats...
/* fun exercise around aunt Lily and her cats... */
(function (owner) {
function randomInt(i) {
return Math.floor(Math.random() * i);
}
function randomText() {
var texts = [
@Chris927
Chris927 / fileupload-experiment.html
Created April 24, 2012 15:04
Use programmatic file upload (via plugin) after asking questions to user
<!--
see also: https://github.com/blueimp/jQuery-File-Upload/issues/473
This didn't work with an 'old' version of the plugin, try the latest one.
Idea is to do file upload all programmatically, thus only sending files once user has confirmed what to do with the files.
-->
<div class="row">
<div class="span10">
@Chris927
Chris927 / demo.diff
Created April 23, 2012 15:51
Diff of the code changes we did in last week's session
diff --git a/grails-app/views/layouts/main.gsp b/grails-app/views/layouts/main.gsp
index 4e70434..8d3dcae 100644
--- a/grails-app/views/layouts/main.gsp
+++ b/grails-app/views/layouts/main.gsp
@@ -12,14 +12,23 @@
<link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon">
<link rel="apple-touch-icon" href="${resource(dir: 'images', file: 'apple-touch-icon.png')}">
<link rel="apple-touch-icon" sizes="114x114" href="${resource(dir: 'images', file: 'apple-touch-icon-retina.png')}">
+ <link rel="stylesheet" href="/todo/css/bootstrap.css" />
<!-- <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css"> -->
@Chris927
Chris927 / test.html
Created March 9, 2012 07:05
HTML5 / pure javascript to post the 'modified date' when uploading a file
<!doctype html>
<html>
<head>
<title>Just testing...</title>
</head>
<body>
<script type="text/javascript">
function updateFile() {
var files = document.getElementById("uploadInput").files;
var nFiles = files.length;