Skip to content

Instantly share code, notes, and snippets.

View kapillamba4's full-sized avatar

Kapil Lamba kapillamba4

  • Flipkart
  • Delhi, India
View GitHub Profile
@kapillamba4
kapillamba4 / template.cpp
Created December 26, 2018 08:11 — forked from sananth12/template.cpp
Competitive programming template (C++)
#include <iostream>
#include <cmath>
#include <algorithm>
#include <limits>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <time.h>
@kapillamba4
kapillamba4 / window-auth-popup.es6.js
Created September 18, 2018 12:50 — forked from gauravtiwari/window-auth-popup.es6.js
Promise based popup window for server oAuth
/* global window */
const popup = (url) => {
const windowArea = {
width: Math.floor(window.outerWidth * 0.8),
height: Math.floor(window.outerHeight * 0.5),
};
if (windowArea.width < 1000) { windowArea.width = 1000; }
if (windowArea.height < 630) { windowArea.height = 630; }
@kapillamba4
kapillamba4 / .eslintrc.js
Created September 15, 2018 10:46 — forked from dmnsgn/.eslintrc.js
.eslintrc Google JavaScript Style Guide (eslint v0.24.1)
{
// http://eslint.org/docs/rules/
"env": {
"browser": true, // browser global variables.
"node": false, // Node.js global variables and Node.js-specific rules.
"worker": false, // web workers global variables.
"amd": false, // defines require() and define() as global variables as per the amd spec.
"mocha": false, // adds all of the Mocha testing global variables.
"jasmine": false, // adds all of the Jasmine testing global variables for version 1.3 and 2.0.
@kapillamba4
kapillamba4 / DockerCleanupScripts.md
Created August 5, 2018 15:16 — forked from johnpapa/DockerCleanupScripts.md
Docker Cleanup Scripts

Docker - How to cleanup (unused) resources

Cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@kapillamba4
kapillamba4 / docker-cleanup
Last active August 24, 2018 17:59 — forked from mattberther/docker-cleanup
Thorough docker cleanup script
#!/bin/sh
# Cleanup docker files: untagged containers and images.
#
# Use `docker-cleanup -n` for a dry run to see what would be deleted.
exited_containers() {
docker ps -a -q -f status=exited
}
untagged_containers() {
@kapillamba4
kapillamba4 / better-nodejs-require-paths.md
Created July 25, 2018 20:01 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@kapillamba4
kapillamba4 / linux-fake-webcam-loop.sh
Created July 25, 2018 16:05 — forked from zburgermeiszter/linux-fake-webcam-loop.sh
Loop video file as fake webcam device with ffmpeg
ffmpeg -re -f concat -i <(for i in {1..9999}; do printf "file '%s'\n" input.mp4; done) -f v4l2 /dev/video1 && !!
@kapillamba4
kapillamba4 / async-foreach.js
Created July 8, 2018 19:02 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@kapillamba4
kapillamba4 / postgres-cheatsheet.md
Created June 23, 2018 08:58 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)