Skip to content

Instantly share code, notes, and snippets.

View appsparkler's full-sized avatar
🏄‍♂️
Surfing the web...

Aakash appsparkler

🏄‍♂️
Surfing the web...
View GitHub Profile
@appsparkler
appsparkler / structure-and-interpretation-of-computer-programs.markdown
Last active April 15, 2022 05:41
Structure and Interpretation of Computer Programs Notes
@appsparkler
appsparkler / functional-programming.markdown
Last active April 15, 2022 06:18
Functional Programming Notes

Functional Programming

1. Declarative v/s Imperative

FP looks at things as "What to do?" rather than "How to do it?"

  // imperative way of doing things
  const findMean = (...numbers) => {
    let x = 0;
    numbers.forEach((number) => {
      x += number;
@appsparkler
appsparkler / javascript-diary.markdown
Last active June 8, 2021 23:29
My Javascript Diary

Javascript Diary

Callbacks, FP

Callbacks are a great tool to achieve SRP. For ex. the following function is responsbile for submitting forms and nothing else.

// SRP
const submitForm = ({apiUrl, payload, onSuccess, onFailure}) => {
  fetch(apiUrl, payload)
    .then((res) => {
@appsparkler
appsparkler / medium-b98f765612b4-take1.js
Last active January 19, 2021 04:17
Conditionally setting a value
const getIsDisabled = ({fromDate, toDate, selectedKey) => {
let isDisabled = true; // set the initial value to true
if(selectedKey === 'valueA') {
isDisabled = false;
} else if(selectedKey === 'valueB') {
if(fromDate) {
const isfromDateValid = moment(fromDate).isValid();
const isfromDateGreaterThanOrEqualToToday = moment().diff(fromDate) <= 0;
if(isfromDateValid && isfromDateGreaterThanOrEqualToToday) {
isDisabled = false
@appsparkler
appsparkler / medium-72e4570f5784-promises.js
Last active January 19, 2021 03:10
Getting more from promises.
// a sample array of items.
const values = [
'item1',
'item2'
]
// checkValue(item) is an async that returns true or false.
const promises = values.map(async(item) => checkValue(item).catch(err => err))
const results = await Promise.all(results)
console.log(results); // ['true', 'false'];
@appsparkler
appsparkler / cordova writing file.js
Created March 9, 2019 10:33
Cordova Writing On An Existing File If Already Available (updating data)
var fileName = 'test-450.json';
var fileData;
var savedFileEntry = {};
promise_getPersistentDirectoryEntry()
.then(promise_fileEntry.bind(null, fileName, { create:false }))
.then(save_fileEntry)
.then(promise_file)
.then(promise_fileContent)
var filters = ""
$('img').toArray().forEach(iterateImageElements.bind(this));
console.log(filters)
function iterateImageElements(){
var _this = arguments[0];
filters += getImagePaths.apply(_this, arguments) + "\n";
}
All Chrome Scripts here.
/*
gist: https://gist.github.com/appsparkler/7ce9d5e7e607a95c483d88fabb9a611e
% - The percent sign represents zero, one, or multiple characters
_ - The underscore represents a single character
*/
{
let domain = "https://env01-author.kpmg.com";
let url = `${domain}/bin/querybuilder.json`;
function colorLog(msg1, msg2) {
var css = "text-shadow: -1px -1px hsl(0,100%,50%), 1px 1px hsl(5.4, 100%, 50%), 3px 2px hsl(10.8, 100%, 50%), 5px 3px hsl(16.2, 100%, 50%), 7px 4px hsl(21.6, 100%, 50%), 9px 5px hsl(27, 100%, 50%), 11px 6px hsl(32.4, 100%, 50%), 13px 7px hsl(37.8, 100%, 50%), 14px 8px hsl(43.2, 100%, 50%), 16px 9px hsl(48.6, 100%, 50%), 18px 10px hsl(54, 100%, 50%), 20px 11px hsl(59.4, 100%, 50%), 22px 12px hsl(64.8, 100%, 50%), 23px 13px hsl(70.2, 100%, 50%), 25px 14px hsl(75.6, 100%, 50%), 27px 15px hsl(81, 100%, 50%), 28px 16px hsl(86.4, 100%, 50%), 30px 17px hsl(91.8, 100%, 50%), 32px 18px hsl(97.2, 100%, 50%), 33px 19px hsl(102.6, 100%, 50%), 35px 20px hsl(108, 100%, 50%), 36px 21px hsl(113.4, 100%, 50%), 38px 22px hsl(118.8, 100%, 50%), 39px 23px hsl(124.2, 100%, 50%), 41px 24px hsl(129.6, 100%, 50%), 42px 25px hsl(135, 100%, 50%), 43px 26px hsl(140.4, 100%, 50%), 45px 27px hsl(145.8, 100%, 50%), 46px 28px hsl(151.2, 100%, 50%), 47px 29px hsl(156.6, 100%, 50%), 48px 30px hsl(162, 100%,