Skip to content

Instantly share code, notes, and snippets.

View topliceanu's full-sized avatar
💭
🚀

Alexandru Topliceanu topliceanu

💭
🚀
View GitHub Profile
@topliceanu
topliceanu / testUtil.coffee
Last active August 29, 2015 13:58
A implementation of the _.any api but for asynchronous computation and Q promises.
assert = (require 'chai').assert
Q = require 'q'
util = require './util'
describe '.any()', ->
it 'should fail when no promise resolves', (done) ->
fns = [
@topliceanu
topliceanu / setters_and_getters.coffee
Created March 17, 2014 08:44
example of how to implement setters and getters in a coffeescript class. not accessible to children classes.
###
Utility to add setters and getters to a class in coffeescript.
@see https://github.com/thingdom/node-neo4j/blob/master/lib/PropertyContainer._coffee
###
class A
get = (props) =>
@::__defineGetter__ name, getter for name, getter of props
@topliceanu
topliceanu / tweet-parser.coffee
Created February 19, 2013 14:07
method to extract transform users and links in tweets into actual links
parseTweet = (tweet) ->
###
This method parses a plain tweet text and outputs html
containing links for all @usernames, #hashtags and links in it.
@param {String} tweet
@param {String} - html output
###
links = [
/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g
(url) ->
@topliceanu
topliceanu / alter-ajax-response.js
Created November 30, 2012 10:58
A centralized way to modify jquery ajax responses. Usefull in testing where you need semi-mocks
var alterResponse = function (opts) {
/**
* Function modifies $.ajax responses
* by allowing you to modify ajax response object before each bound success callback.
* Currently it supports only `success` callbacks, `error` and `complete` support to come.
* @param {RegExp} opts.urlMatch - use this to filter calls by url
* @param {String} opts.dataType - Optional - use this to filter calls by response type
* @param {Function} opts.successWrapper - function that gets called before each ajax callback
* - function (options:Object, originalOptions:Object, jqXHR:jQuery.XHR, originalSuccess: Function)
*/
@topliceanu
topliceanu / description.markdown
Created May 5, 2012 10:16
lists all user defined globals attached to [window]

This bookmarklet can be used to keep track of global variables attached to window.

It displays the user-defined global variables by comparing all properties attached on current window to all standard properties extracted from an empty iframe.

To install, create a new bookmark in your bookmark bar and copy-paste the contents of listGlobals.bookmarklet

@topliceanu
topliceanu / node-csv-parser-pipeable.js
Created April 19, 2012 13:16
script for adapting node-csv to allow .pipe()
var streams = require('stream');
var events = require('events');
var util = require('util');
var csv = require('csv');
var InputStream = function () {};
util.inherits(InputStream, streams.Stream);
var OutputStream = function () {};
util.inherits(OutputStream, events.EventEmitter);
@topliceanu
topliceanu / extend.es5.js
Created March 6, 2012 11:43
extends objects, similar in functionality to $.extend or _.extend
// jquery style `extend` work in ES5 compatible envs
var extend = function (obj) {
var args = Array.prototype.slice.call(arguments, 1);
args.forEach( function (source) {
for (var prop in source)
if (source.hasOwnProperty(prop)) obj[prop] = source[prop];
});
return obj;
};
@topliceanu
topliceanu / documentLocalStorage.js
Created March 3, 2012 11:05
store data in localstorage, api similar to document databases
// stores arrays binded to keys in localstorage
(function (win) {
var isStorage = function (obj) {
return (Object.prototype.toString.call(obj) === '[object Storage]');
};
var decode = function (str) {
try {
var arr = JSON.parse(str);
if (!Array.isArray(arr)) return false;
return arr;
@topliceanu
topliceanu / requestGzip.js
Created February 19, 2012 16:22
Stream downloader of web resources, based on mikeal's request, but processed first through zlib if necessary
var request = require('request');
var zlib = require('zlib');
// A two-way passthrough Stream, made by @felixge
// https://github.com/felixge/node-passthrough-stream/blob/master/lib/passthrough_stream.js
var PassthroughStream = function () {
this.writable = true;
this.readable = true;
}
util.inherits(PassthroughStream, streams.Stream);