Skip to content

Instantly share code, notes, and snippets.

@EGreg
EGreg / gist:1678415
Created January 25, 2012 20:17 — forked from fennb/gist:1124580
Asynchronous loop issues illustrative example
// Illustrative case
// YEAH -- ILLUSTRATIVE OF THE FACT THAT YOU CAN ISSUE PARALLEL QUERIES TO THE DATABASE INSTEAD OF SERIAL ONES LIKE A DUMB THREADED IMPLEMENTATION THAT IS INFERIOR FOR DOING WEB SERVERS
function (recentBlogPostIds, callback) { // obviously you need this, but use callback instead of return
var results = {};
var count = 0;
for (var i = 0; i < recentBlogPostIds.length; i++) {
var blogPostId = recentBlogPostIds[i];
@EGreg
EGreg / openletter.txt
Created May 3, 2011 00:33
The most open letter ever
This is the most open letter ever. Other authors claim their letters are "open" because you can all read them, but in reality, they are nothing but the rants of one person, which you might not even completely agree with, or will piss you off.
By contrast, this letter is truly open and gives you the freedom to fork and modify it. Pissed about Mike Arrington investing? Want to give Richard Stallman some personal advice to stop publicly mentioning conspiracy theories he may or may not believe in? The choice is yours. Simply fork this letter and post it on Hacker News and other places. Track its changes, and see what happens.
Anything you wanted to write about lately?
--- THE THREE LINES ---
This letter is licensed under the GNU Public License. http://www.gnu.org/licenses/gpl.html
You may fork it but you must include these three lines exactly as they appear at the bottom of the letter.
@EGreg
EGreg / pipe.js
Created December 16, 2010 01:22
Lets you pipe data and create control flow structures
/*
* Creates a callback to be called after multiple functions are done
* Usage:
* var p = Q.pipe(function (params, subjects) {
* // arguments that were passed are in params.user, params.stream
* // this objects that were passed are in subjects.user, subjects.stream
* }, ['user', 'stream]);
* mysql("SELECT * FROM user WHERE user_id = 2", p.fill('user'));
* mysql("SELECT * FROM stream WHERE publisher_id = 2", p.fill('stream'));
*
@EGreg
EGreg / pipe.js
Created December 16, 2010 02:40
Piping baby
/*
* Sets up control flows involving multiple callbacks and dependencies
* Usage:
* var p = Q.pipe(function (params, subjects) {
* // arguments that were passed are in params.user, params.stream
* // this objects that were passed are in subjects.user, subjects.stream
* }, ['user', 'stream]);
* mysql("SELECT * FROM user WHERE user_id = 2", p.fill('user'));
* mysql("SELECT * FROM stream WHERE publisher_id = 2", p.fill('stream'));
*
@EGreg
EGreg / FSURLCache.m
Created July 10, 2015 21:45
Intercepting requests on iOS
#import "FSURLCache.h"
#import <MobileCoreServices/MobileCoreServices.h>
@implementation FSURLCache
- (NSString*) fileMIMEType:(NSString*) file {
NSDictionary *mimeDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"image/png",
@"png",
@EGreg
EGreg / interests.log
Created April 6, 2015 10:49
Adding and removing interests
-----
[2015-04-03 11:16:10] (gmba.local) Groups: DELETE slots: (publisherId,streamName) from url: http://gmba.local/Groups/action.php/Streams/interest?Q.ajax=json&Q.slotNames=publisherId%2CstreamName&Q.method=DELETE&Q.nonce=d454a3454f9a29f2cf2c18d376183325
[2015-04-03 11:16:10] (gmba.local) Groups:
SELECT *
FROM Groups.users_user
WHERE `id` = 'ohrxqrzb'
LIMIT 1
@EGreg
EGreg / objectivism
Created March 28, 2015 22:52
Basic question about objectivism
srogers
you cannot possibly expect to have a discussion about whether Objectivism is consistent with “screwing people over” if you hold that man’s nature is subjective
mgin
The Objectivist ethics holds that the actor must always be the beneficiary of his action and that man must act for his own rational self-interest. But his right to do so is derived from his nature as man and from the function of moral values in human life—and, therefore, is applicable only in the context of a rational, objectively demonstrated and validated code of moral principles which define and determine his actual self-interest. It is not a licens
mgin
altruists’ image of a “selfish” brute nor to any man motivated by irrational emotions, feelings, urges, wishes or whims.
mgin
well that's not directly applicable, but there's an indication
srogers
While you may have read a lot of stuff, you clearly disagree with most of it, in various ways that are more fundamental than ethics
@EGreg
EGreg / Location
Created March 16, 2015 16:47
Groups/location Controller
<?php
function Groups_location_response_column($params)
{
$user = Users::loggedInUser();
if (!$user) {
Q_Response::redirect("Groups/groups");
}
$miles = array();
foreach (Q_Config::expect('Places', 'nearby', 'miles') as $m) {
@EGreg
EGreg / group.handlebars
Created March 15, 2015 19:44
Group template
{{&tool "Streams/participants" "group" max=10 maxShow=10 showSummary=false showControls=true showBlanks=true }}
<div class="Q_big_prompt Groups_going_prompt">
Are you in?
<span class="Groups_going" data-going="{{going}}">
<span data-going="no" class="Groups_no {{no}}">No
</span><span data-going="maybe" class="Groups_maybe {{maybe}}">Maybe
</span><span data-going="yes" class="Groups_yes {{yes}}">Yes</span>
</span>
</div>
@EGreg
EGreg / Q.Promises.js
Created November 11, 2014 22:36
A clear and tested Promises implementation
/**
* Q Promises implementation
* @module Q
*/
(function (Q) {
/**
* Q.Promise constructor.
* Call the .fulfill(...) or .reject(...) method to
* signal that the promise is fulfilled or rejected.