Skip to content

Instantly share code, notes, and snippets.

View anshuraj's full-sized avatar
🎯
Focusing

Anshu Raj anshuraj

🎯
Focusing
View GitHub Profile
const getQueryVariable = variable => {
const query = window.location.search.substring(1);
const params = query.split("&");
for (let i=0;i<params.length;i++) {
const pair = params[i].split("=");
if(pair[0] == variable) {
return pair[1];
}
}
return false;
@anshuraj
anshuraj / center-image.html
Created July 20, 2018 13:15
Center image horizontally and vertically inside a div.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="responsive-container">
@anshuraj
anshuraj / interactive tutorials
Last active April 17, 2019 05:51
Interactive Learning Tutorials
CSS Dinner: https://flukeout.github.io/
Flexbox Froggy: http://flexboxfroggy.com/
CSS Garder: http://cssgridgarden.com/
Open VIM: http://www.openvim.com/
Try Redis: http://try.redis.io/
@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
// 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 / 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
(function() {
try {
throw new Error();
} catch(x) {
var x = 1, y = 2;
console.log('x ', x);
}
console.log('x ', x);
console.log('y ', y);
})();
// 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) {
@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);
}
}
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);