Skip to content

Instantly share code, notes, and snippets.

@madhums
madhums / moveable-modal.js
Last active May 10, 2024 13:11
Making angular-ui bootstrap modal moveable
'use strict';
/**
* Moveable modal
*
* You need to set the options of the provider.
*
* Requirements:
*
* You need angular-ui/bootstrap module
@madhums
madhums / node-file-structure.js
Last active August 29, 2015 14:09
structure for writing module/api in node
/**
* Module dependencies.
*/
var http = require('http'); // native modules first
var mongoose = require('mongoose'); // npm modules second
var config = require('config'); // modules that are required via NODE_PATH third
var fmt = require('./format-date'); // local modules fourth
var oauth = require('../../oauth'); // relative modules last
@madhums
madhums / res.js
Last active August 29, 2015 14:06
returned object
function callback (err, res) {
// res.request.href => is this is url of the uploaded file?
}
fs.createReadStream('image-1.png').pipe(client.upload({
container: 'a-container',
remote: 'image-1.png'
}), callback);
// res =>
/*
@madhums
madhums / base64-image-upload.js
Created September 14, 2014 17:37
save base64 encoded image
/*
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674
*/
var fs = require('fs');
// string generated by canvas.toDataURL()
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// strip off the data: url prefix to get just the base64-encoded bytes
@madhums
madhums / .jshintignore
Last active August 29, 2015 14:04
Setup jshint and pre-commit checks
node_modules
public/components
public/dist
@madhums
madhums / .jshintrc
Last active August 29, 2015 14:04
jshint
{
"bitwise": false,
"immed": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"trailing": true,
"boss": true,
"eqnull": true,
var http = require('http')
var i = 0;
var j = 0;
// write data to request body
setInterval(function(){
console.log('\n');
i = i + 1;
console.log('Sending request: ' + i);
http.get("http://localhost:3000", function(res) {
j = j + 1;
@madhums
madhums / gist:71eaa203f11a428cb8a2
Created June 14, 2014 21:04
remove files of a type recursively
$ find app/views -name "*.jade" -type f|xargs rm -f
@madhums
madhums / flatten.js
Created January 20, 2014 20:28
flatten an array containing prev, next nested objects
function (obj, arr) {
var index = arr.push(obj);
if (obj.prev) {
arr.splice.apply(arr, [index - arr.length, 0].concat(this.timeline(obj.prev, [])));
}
if (obj.next) {
arr.splice.apply(arr, [index + arr.length, 0].concat(this.timeline(obj.next, [])));
}
return arr;
}