Skip to content

Instantly share code, notes, and snippets.

View th3hunt's full-sized avatar
🎯
Focusing

Stratos Pavlakis th3hunt

🎯
Focusing
  • Blueground
  • Athens
View GitHub Profile
@th3hunt
th3hunt / bootstrapErrorRenderer.js
Created February 7, 2014 11:28
snippet of a bootstrap 2.3 style error renderer for use with backbone views
var errorRenderer = {
valid: function (view, attr, selector) {
var control, group;
control = view.$('[' + selector + '=' + attr + ']');
group = control.parents(".control-group");
group.removeClass("error");
if (control.data("error-style") === "tooltip") {
if (control.data("tooltip")) {
return control.tooltip("hide");
@th3hunt
th3hunt / s3upload-samples.js
Last active August 29, 2015 13:56
Sample usages of my extension to blueimp.fileupload, s3upload
// simple usage
// 2 retries on S3
$('input#file').s3upload({
registerUrl: 'foo/bar',
registerMethod: 'PUT',
submitStrategy: {
retries: 2
}
})
@th3hunt
th3hunt / backbone.fwd.js
Created June 5, 2014 10:38
backbone.fwd + :target option
// backbone.fwd
// ------------
// Forward events from a source, through a target object
//
// v0.1.0
// Copyright (C)2014 Muted Solutions, LLC.
// Distributed under MIT license
//
// https://github.com/derickbailey/backbone.fwd
// Support routines for automatically reporting user timing for common analytics platforms
// Currently supports Google Analytics, Boomerang and SOASTA mPulse
// In the case of boomerang, you will need to map the event names you want reported
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable:
// rumMapping = {'aft': 'custom0'};
(function() {
var wtt = function(n, t, b) {
t = Math.round(t);
if (t >= 0 && t < 3600000) {
// Google Analytics
@th3hunt
th3hunt / umd.js
Created July 21, 2014 10:20
Universal Module Loader - copied from Jim Cowart's blog post
(function (root, factory) {
if(typeof define === "function" && define.amd) {
// Now we're wrapping the factory and assigning the return
// value to the root (window) and returning it as well to
// the AMD loader.
define(["postal"], function(postal){
return (root.myModule = factory(postal));
});
} else if(typeof module === "object" && module.exports) {
// I've not encountered a need for this yet, since I haven't
@th3hunt
th3hunt / import_honeybadger_notices.js
Last active August 29, 2015 14:05
Import certain honeybadger faults into a mongo DB
var args = process.argv.slice(2),
PROJECT_ID = args[0],
FAULT_ID = args[1],
// MONGO
MONGODB_URI = 'mongodb://localhost:27017/honeybadger',
mongodb = require('mongodb'),
mongoclient,
collection,
/* This shows how to use Object.create */
/** BASE MODEL **********************************/
function BaseModel(collection) {
this.collection = collection;
}
BaseModel.prototype.getCollection = function() {
return this.collection;
@th3hunt
th3hunt / introrx.md
Last active August 29, 2015 14:08 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@th3hunt
th3hunt / extract_css3_rules.js
Created November 21, 2014 14:47
Extract CSS3 rules
var styleSheets = document.styleSheets
, len = styleSheets.length
, keyframeRules = [];
function extractKeyframes(styleSheet) {
var rules = styleSheet.rules;
rules.forEach = Array.prototype.forEach;
// helper to create proper asset paths if an asset host is configured
App.assets = {
assets : {
<% AssetsUtil.images.each do |img| %>
"<%= img %>" : "<%= asset_path(img) %>",
<% end %>
},