Skip to content

Instantly share code, notes, and snippets.

View svapreddy's full-sized avatar
💭
Don't miss a dime to grab a nickel

Prathap Reddy svapreddy

💭
Don't miss a dime to grab a nickel
  • CA, United States
View GitHub Profile
// STEPS:
// Preferred Browser - Google Chrome Latest
// 1. Open ADP Paychecks Page. You will see the paychecks displayed with ID and date range.
// 2. Open Developer Tools by Mouse Right Click -> Inspect Element. Now, Select Console Tab (Usually Second Tab)
// 3. Paste the Below code and press Enter.
// 4. Once all the paychecks are downloaded to your Downloads Folder, goto next page of Paychecks and paste the code again in the Console.
function downloadURI(uri, name) {
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "http")))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
;;(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
Problem: https://gist.github.com/timoxley/a34546c28c92025d040a391400ba5eb7
Solution: fns.forEach([].forEach.bind([1]))
Explanation: [].forEach.bind(someArray) will return a forEach function binded with passed `someArray`. So we can use this as iterator for `fns.forEach`. But the problem is fns.forEach will be executed `fns.length` times on `[].forEach.bind(someArray)` So each function inside fns will be called fns.length times.
fns.forEach.call(fns, [].forEach.call(fns)) // Will execute each function fns.length times
fns.forEach.call(fns, [].forEach.call([1,2])) // Will execute each function 2 times
fns.forEach.call(fns, [].forEach.call([1])) // Will execute each function 1 time
@svapreddy
svapreddy / jsontoul.js
Last active August 29, 2015 14:19
Nested JSON to HTML Lists
/*Description:
* This utility can be used to generate html structure for Nested JSON structures like tree.
* You can customize this as you need to acomplish your own html structure.
* */
function toTree(data, nestedKey, transformer) {
var str = [];
var traverse = function (_obj) {
str[str.length] = "<ul>";
(function (obj) {
@svapreddy
svapreddy / CalendarMonth.js
Last active February 15, 2023 05:57
A small util to generate Calendar Model for any given month and Year
/* Expects month to be in 1-12 index based. */
var monthInformation = function(year, month){
/* Create a date. Usually month in JS is 0-11 index based but here is a hack that can be used to calculate total days in a month */
var date = new Date(year, month, 0);
/* Get the total number of days in a month */
this.totalDays = date.getDate();
/* End day of month. Like Saturday is end of month etc. 0 means Sunday and 6 means Saturday */
this.endDay = date.getDay();
date.setDate(1);
/* Start day of month. Like Saturday is start of month etc. 0 means Sunday and 6 means Saturday */
/*
Here are some methods that work very efficiently and acts as fallback to many fast ass DOM libraries
*/
document.querySelector('selector'); // selector is same as in querySelectorAll()
/*
Usage:
var firstP = document.querySelector('p'); - It gives first 'p' element in Document.
var firstPinsideDiv = someDiv.querySelector('p'); - It gives first 'p' element in someDiv.
/*
Here are few ways to use slice for different use cases.
I am just adding few regular usecases I am able to recollect at this point of time. Will add more later.
*/
var arr = [1, 2, 3, 4, 5, 6, 7, 8];
// Traditional use.
arr.slice(0, 2); // result is [1, 2]
arr.slice(0, 3); // result is [1, 2, 3]
// Author : Prathap Reddy SV
var LStorage = (function () {
function LStorage() {
this.localStorage = JSON.parse(JSON.stringify(localStorage));
// or new Function("return JSON.parse('" + JSON.stringify(localStorage) + "')")();
}
LStorage.prototype.setItem = function (key, val) {
if(this.localStorage[key] == val) return;
this.localStorage[key] = val;
// Author : Prathap Reddy SV
// Purpose : Show an Example of the code structure I use.
var Example = (function($, document, window, undef){
// Bake your Object inside.
function Example(a, b){
this.a = a === undef ? 0 : a;
this.b = b === undef ? 0 : b;
}
// Private