Skip to content

Instantly share code, notes, and snippets.

View abrjagad's full-sized avatar

Abraham Jagadeesh abrjagad

View GitHub Profile
@abrjagad
abrjagad / promise polyfill.js
Created February 3, 2022 20:32
promise polyfill
class Prom {
constructor(promiseCallback) {
this.state = "pending";
this.value = undefined;
this.calledResolve = false;
this.calledReject = false;
this.innerResolve = () => {};
this.innerReject = () => {};
promiseCallback(this.resolved.bind(this), this.rejected.bind(this));
}
@abrjagad
abrjagad / gist:cb829b7df3a4768823bf88208e11499a
Created October 18, 2018 03:37 — forked from andphe/gist:3232343
Export your links from Safari reading list
/usr/bin/plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist | grep -E -o '<string>http[s]{0,1}://.*</string>' | grep -v icloud | sed -E 's/<\/{0,1}string>//g'
@abrjagad
abrjagad / strip_html.js
Last active October 6, 2018 04:50
Strip HTML tags and gives array with only valid elements
var a = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<a href="1.html">Hello World</a>

Command Line Shortcuts

Move all files from Subfolder to this folder

find . -mindepth 2 -type f -print -exec mv {} . ;

Delete folders recursively

find . -name "node_modules" -type d -print -exec rm -rf '{}' +

find . -name "imagewithcta" -type d -print

concatenatedArray=($(ls $Dir) $(ls $AnotherDir))
Array=()
Array+=("value")
Array+=("AnotherValue")
echo ${Array[@]}
echo ${#Array[@]}
@abrjagad
abrjagad / bash_bubble_sort.sh
Created August 31, 2018 13:31
Bash: Sort Array by value's length
# Performing Bubble sort
for ((i = 0; i<${#array[@]}-1; i++))
do
# echo $i
for((j = 0; j<${#array[@]}-1; j++))
do
if ((${#array[j]} < ${#array[$((j+1))]}))
then
temp=${array[$j]}
array[$j]=${array[$((j+1))]}
var f = ['women','men'];
var context = require.context('./', true, /.scss$/);
var module = context.keys();
module.sort(function(a,b){
return (f.indexOf(a.split('/')[1])>f.indexOf(b.split('/')[1]))
});
console.log(module);
//module.forEach(context)
//// execute them
module.forEach(function(key) {
(function () {
function log(x) {
console.log('My value: ' + x);
}
var funcs = [];
for (var i = 0; i < 3; i++) {
funcs[i] = log.bind(null, i);
}
var BrowserDetectMixin = {
// Lifted from:
// http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie/21712356#21712356
detectIE: function() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
$.event.special.abetap = {
delegateType: "tap",
bindType: "tap",
handle: function (event) {
var handleObj = event.handleObj;
var targetData = jQuery.data(event.target);
var ret = null;
event.preventDefault();