Skip to content

Instantly share code, notes, and snippets.

View narainsagar's full-sized avatar
👋
email me for projects or relocation roles!!

Narain M. narainsagar

👋
email me for projects or relocation roles!!
View GitHub Profile
@narainsagar
narainsagar / mac-apps.md
Last active September 17, 2015 13:23 — forked from erikreagan/mac-apps.md
Mac developer must-haves

Mac web developer apps

This gist's comment stream is a collection of webdev apps for OS X. Feel free to add links to apps you like, just make sure you add some context to what it does — either from the creator's website or your own thoughts.

— Erik

alias glp="git log --color -p | less -R"
alias glg="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit | less -R"
alias hlog='git log --date-order --all --graph --format="%C(green)%h %Creset%C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset %s"'
alias cdg="cd \$(git rev-parse --show-toplevel)"
'use strict';
/*
# Javascript Prototyping Best Practices
* To create a class, create a constructor function with a `Name` and assign
it to a variable of the same `Name`.
* In this constructor only define properties using `this.prop` notation
@narainsagar
narainsagar / JavaScriptTestingWithGruntMochaAndChai.md
Created October 17, 2015 11:21
JavaScript Testing with Grunt, Mocha and Chai

JavaScript Testing with Grunt, Mocha and Chai

In the following post I would like to introduce one way how you can setup your testing workflow for JavaScript development. The central components in the testing environment are Grunt, Mocha and Chai that I will cover from the introduction and installation of each component to the cooperation of all components for the execution of tests.

If you are already an experienced Grunt user and just look for the Gruntfile.js and the Mocha / Chai setup just skip the central components section and skip to the installing components part.

You can find the sample project with all code at GitHub on: https://github.com/maicki/sample-js-testing-grunt-mocha-chai

Central Components

@narainsagar
narainsagar / detect-private-browsing.js
Created October 26, 2015 11:32 — forked from cou929/detect-private-browsing.js
Detect private browsing mode (InPrivate Browsing or Incognito).
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);
@narainsagar
narainsagar / PHPExcel_Basics.md
Created November 9, 2015 06:43 — forked from r-sal/PHPExcel_Basics.md
PHPExcel Notes and code snippets

Basics

Creating a new PHPExcel Object.

    $this->PHPExcel = new PHPExcel();

Working with sheets

Creating a new sheet:

@narainsagar
narainsagar / dom_jquery_swap_elements
Last active October 8, 2016 23:33
Swap two DOM elements using jQuery (Events and a possible focus or Bindings wouldn't be lost during/after swapping!)
/* A very simple and nice function to swap DOM elements */
// Solution #1
function swap($elementA, $elementB) {
var temp = $('<div>').insertAfter($elementA);
$elementA.insertAfter($elementB);
$elementB.insertBefore(temp);
temp.remove();
}
@narainsagar
narainsagar / php_export_html_to_excel_via_phpexcel
Last active May 8, 2019 07:52
Export Html contents to Excel file using PHPExcel
<?php
/*
// save this file to: ExcelService.class.php
Create new folder 'libs' under your project dir, and download PHPExcel-1.8 library .zip from here..
use this clone url: [email protected]:PHPOffice/PHPExcel.git
OR https://github.com/PHPOffice/PHPExcel.
*/
define('TMP_FILES', "../temp/"); // temp folder where it stores the files into.
@narainsagar
narainsagar / mongodb-date-range
Created February 8, 2016 20:07
Finding number of records where date is in date range?
This is the easiest way you can:
var thisDate = ISODate("2016-01-07T00:00:00Z");
Model.find({
startDate: {
'$lte': thisDate
},
endDate: {
'$gte': thisDate