Skip to content

Instantly share code, notes, and snippets.

View DanisHack's full-sized avatar
:octocat:

Muhammad Danish DanisHack

:octocat:
View GitHub Profile
@DanisHack
DanisHack / transparent-gif.js
Created November 17, 2017 09:28 — forked from sspencer/transparent-gif.js
Serve a transparent GIF from NodeJS
// Two ways to serve transparent GIF
var buf = new Buffer([
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
0x02, 0x44, 0x01, 0x00, 0x3b]);
res.send(buf, { 'Content-Type': 'image/gif' }, 200);
@DanisHack
DanisHack / Statistics.js
Created September 18, 2017 10:47 — forked from Sirfrummel/Statistics.js
Loading Segment.io analytics.js open source version async
// Create a dummy analytics object until real loaded
window.analytics || (window.analytics = []);
window.analytics.methods = ['identify', 'track', 'trackLink', 'trackForm', 'trackClick', 'trackSubmit', 'page', 'pageview', 'ab', 'alias', 'ready', 'group', 'on', 'once', 'off'];
window.analytics.factory = function(method) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
window.analytics.push(args);
return window.analytics;
};

Setup remote git repo on EC2

Create a bare repository

$ mkdir <repo-name>.git
$ cd <repo-name>.git
$ git init --bare
@DanisHack
DanisHack / folder-traverse.js
Created April 13, 2016 14:47
Traverse folder directive in angularJS
'use strict';
angular.module('traverse.folder', [])
.factory('folderTraverse', ['$http', '$log', '$q', '$timeout', function(http, log, q, timeout){
var filesInFolder = [];
var traversalAPI = {};
traversalAPI.getFiles = function(dataTransfer){
var defer = q.defer();
@DanisHack
DanisHack / Gruntfile.js
Created October 21, 2015 12:18 — forked from markgoodyear/01-gulpfile.js
Comparison between gulp and Grunt. See http://markgoodyear.com/2014/01/getting-started-with-gulp/ for a write-up.
/*!
* Grunt
* $ npm install grunt-contrib-uglify grunt-autoprefixer grunt-contrib-cssmin grunt-contrib-imagemin grunt-contrib-sass grunt-contrib-watch grunt-contrib-concat grunt-contrib-clean grunt-contrib-jshint grunt-notify --save-dev
*/
module.exports = function(grunt) {
grunt.initConfig({
// Sass
@DanisHack
DanisHack / .gitignore
Last active August 29, 2015 14:23 — forked from octocat/.gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@DanisHack
DanisHack / scp.txt
Created July 9, 2014 06:14
Using scp to transfer files in Linux
http://infohost.nmt.edu/tcc/help/xfer/scp.html
http://www.tecmint.com/scp-commands-examples/
@DanisHack
DanisHack / mongoInstall.sh
Created July 1, 2014 10:13
install latest stable mongodb on ubuntu
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org