Skip to content

Instantly share code, notes, and snippets.

View anshuraj's full-sized avatar
🎯
Focusing

Anshu Raj anshuraj

🎯
Focusing
View GitHub Profile
@anshuraj
anshuraj / resetiStat.sh
Created June 11, 2021 15:33 — forked from rollxx/gist:2689219
iStat trial reset
rm ~/Library/Preferences/com.bjango.istatmenus.plist
@anshuraj
anshuraj / sum(2)(3)(4).js
Created April 28, 2020 10:31
sum(2)(3)(4)...(n)
function sum (a) {
return function (b) {
if (b) {
return sum(a + b);
} else {
return a;
}
}
}
@anshuraj
anshuraj / getData.js
Created April 25, 2020 12:08
Make API call in node js using https module
async function getData(url) {
return new Promise((resolve, reject) => {
https.get(url, (res) => {
let data = '';
res.on('data', (chunk ) => {
data+= chunk;
})
res.on('end', () => {
data = JSON.parse(data);
resolve(data);
const throttle = (func, delay) => {
let last = 0;
return function (...args) {
const context = this;
const now = new Date().getTime();
if (now - last < delay) {
return;
}
last = now;
return func(args);
@anshuraj
anshuraj / debounce.js
Created April 23, 2020 06:56
Debouncing function
const debounce = function (func, delay) {
let timer;
return function() {
const context = this;
const args = arguments;
clearTimeout(timer);
timer = setTimeout(() => func.apply(context, args), delay);
}
}
// Using recursion to flat object.
function magic(obj, name) {
let myObj = {};
for (let key in obj) {
if (typeof obj[key] !== 'object') {
myObj[name + '_' + key] = obj[key];
} else {
const magicValue = magic(obj[key], name + '_' + key);
// for (let i in magicValue) {
(function() {
try {
throw new Error();
} catch(x) {
var x = 1, y = 2;
console.log('x ', x);
}
console.log('x ', x);
console.log('y ', y);
})();
@anshuraj
anshuraj / gitautocomplete.md
Last active October 7, 2022 11:45
git autocomplete

Download the git-completion.sh file from GitHub:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

Next, add the following to your ~/.bash_profile file:

if [ -f ~/.git-completion.bash ]; then
 . ~/.git-completion.bash
// assign Copy one struct into another of same type
// Accepts pointer to struct
func assign(t interface{}, t2 interface{}) {
s := reflect.ValueOf(t)
s2 := reflect.ValueOf(t2)
if s.Kind() == reflect.Ptr {
s = reflect.Indirect(s)
}
@anshuraj
anshuraj / goResources.txt
Last active May 21, 2019 11:42
Resources to get started on GoLang
1. https://tour.golang.org/welcome/1
2. https://golang.org/doc/effective_go.html
3. https://learnxinyminutes.com/docs/go/
4. https://www.goin5minutes.com
5. https://github.com/astaxie/build-web-application-with-golang/
6. https://gobyexample.com
Other stuff
1. https://medium.com/@IndianGuru/what-has-been-your-biggest-challenge-while-working-with-go-31e11a5e5b8d
2. https://www.youtube.com/watch?v=HxaD_trXwRE