Skip to content

Instantly share code, notes, and snippets.

@rodyhaddad
rodyhaddad / timeago.filter.js
Created June 30, 2013 21:04
timeago filter for angularjs
.filter("timeago", function () {
//time: the time
//local: compared to what time? default: now
//raw: wheter you want in a format of "5 minutes ago", or "5 minutes"
return function (time, local, raw) {
if (!time) return "never";
if (!local) {
(local = Date.now())
}
@attilaolah
attilaolah / domready.coffee
Last active February 13, 2020 17:44
JS & CoffeeScript DOM ready listeners
###
# Based on:
# jQuery JavaScript Library v1.4.2
# http://jquery.com/
#
# Copyright 2010, John Resig
# Dual licensed under the MIT or GPL Version 2 licenses.
# http://jquery.org/license
###
@djds4rce
djds4rce / responseInterceptor.js
Last active December 21, 2015 00:49
Http Response interceptor. Handles 401 requests from the server
//Works for 1.1.x versions. 1.0.x is similar and can be figured out using code comments
myapp.factory('myHttpResponseInterceptor',['$q','$location',function($q,$location){
return {
response: function(response){
return promise.then(
function success(response) {
return response;
},
function error(response) {
if(response.status === 401){
@mbostock
mbostock / .block
Last active February 14, 2024 17:51
Zoomable Circle Packing
license: gpl-3.0
height: 960
redirect: https://observablehq.com/@d3/d3-zoomable-circle-packing
@badsyntax
badsyntax / nodejs.pp
Created December 19, 2013 15:28
Puppet: Installing node.js via nvm
class nodejs {
exec { 'nvm-install':
command => '/usr/bin/curl https://raw.github.com/creationix/nvm/master/install.sh | /bin/sh',
creates => '/home/vagrant/.nvm',
user => 'vagrant',
environment => 'HOME=/home/vagrant',
require => Package['curl']
}
@djavier
djavier / myAJResource.js
Created December 30, 2013 19:30
Extends AngularJS $save method to use Put and Post for Updates and Creates respectively.
var module = angular.module( 'my.resource', [ 'ngResource' ] );
module.factory( 'Resource', [ '$resource', function( $resource ) {
return function( url, params, methods ) {
var defaults = {
update: { method: 'put', isArray: false },
create: { method: 'post' }
};
methods = angular.extend( defaults, methods );
@mlouro
mlouro / gulpfile.js
Last active June 21, 2022 23:20
gulpfile.js with browserify, jshint, libsass, browserSync for livereload, image optimization and system notifications on errors
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var exec = require('child_process').exec;
var notify = require('gulp-notify');
@tjmehta
tjmehta / javascript-object-to-querystring.js
Last active January 28, 2024 22:35
Object to Querystring - JavaScript, JS, JSON
function objectToQuerystring (obj) {
return Object.keys.reduce(function (str, key, i) {
var delimiter, val;
delimiter = (i === 0) ? '?' : '&';
key = encodeURIComponent(key);
val = encodeURIComponent(obj[key]);
return [str, delimiter, key, '=', val].join('');
}, '');
}
@StoneCypher
StoneCypher / repeater.jsx
Created April 16, 2014 18:44
This is how a React repeater control is made (housing html at https://gist.github.com/StoneCypher/10919111 )
/** @jsx React.DOM */
'use strict';
var RepeaterRow = React.createClass({
render: function() {
return <div>Repeater Row {this.props['data-ex']}</div>;
}
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing