Skip to content

Instantly share code, notes, and snippets.

View gggauravgandhi's full-sized avatar
🤓
Something can always be better, nothing is ever complete 🚀

Gaurav gggauravgandhi

🤓
Something can always be better, nothing is ever complete 🚀
View GitHub Profile
@gggauravgandhi
gggauravgandhi / aabbcc.js
Last active August 28, 2016 14:15
Brute Force solution to AA + BB + CC = ABC (Puzzle link : http://mindyourdecisions.com/blog/2016/05/22/aa-bb-cc-abc-sunday-puzzle/)
// Link to jsfiddle : https://jsfiddle.net/gggauravgandhi/eb72685k/
// Gist : https://jsfiddle.net/gggauravgandhi/eb72685k/
(function() {
for (var a = 0; a <= 9; a++) {
for (var b = 0; b <= 9; b++) {
if (b != a) {
for (var c = 0; c <= 9; c++) {
if (c != a && c != b) {
var actualTotal = (a * 11) + (b * 11) + (c * 11);
var targetTotal = (a * 100) + (b * 10) + (c * 1);
@gggauravgandhi
gggauravgandhi / Preferences.sublime-settings.
Last active August 28, 2016 14:05
My sublime config (in use).
{
"added_words":
[
"nodemon",
"Plugin",
"plugins",
"config",
"datetime",
"plugin",
"async",
@gggauravgandhi
gggauravgandhi / naming.js
Last active August 28, 2016 18:38
Function / Variable naming in Javascript Stack
// type-1
var do_maths_add_two_number = function(val_one, val_two){ /*...*/ };
do_maths_add_two_number(10, 90); // Calling type-1
/// can be re-written as
// type-2
var do_maths = function(params){ /*...*/ };
do_maths({ mode : 'add', values[10,90]}); // Calling type-2
// OR
@gggauravgandhi
gggauravgandhi / generate-mysqldump-gz.sh
Last active August 29, 2016 06:33
Generate sql dump file.
#!/bin/bash
printf "Enter host name : "
read host_name
printf "Enter database name : "
read db_name
printf "Enter username name : "
read username
@gggauravgandhi
gggauravgandhi / gfc_l1q1_solution.py
Created June 3, 2017 06:49
Google's Foo.bar Two Array Difference Puzzle (Prison Labor Dodgers)
# Quiz: Prison Labor Dodgers
# ====================
# Commander Lambda is all about efficiency, including using her bunny prisoners for manual labor. But no one's been properly monitoring the labor shifts for a while, and they've gotten quite mixed up. You've been given the task of fixing them, but after you wrote up new shifts, you realized that some prisoners had been transferred to a different block and aren't available for their assigned shifts. And manually sorting through each shift list to compare against prisoner block lists will take forever - remember, Commander Lambda loves efficiency!
# Given two almost identical lists of prisoner IDs x and y where one of the lists contains an additional ID, write a function answer(x, y) that compares the lists and returns the additional ID.
# For example, given the lists x = [13, 5, 6, 2, 5] and y = [5, 2, 5, 13], the function answer(x, y) would return 6 because the list x contains the integer 6 and the list y doesn't. Given the lists x = [14, 27, 1, 4, 2, 50,
@gggauravgandhi
gggauravgandhi / gfc_l2q2_solution.py
Last active June 3, 2017 06:59
Google's Foo.bar Pegs and Gear Puzzle (Gearing Up for Destruction)
# Quiz: Gearing Up for Destruction
# ==========================
# As Commander Lambda's personal assistant, you've been assigned the task of configuring the LAMBCHOP doomsday device's axial orientation gears. It should be pretty simple - just add gears to create the appropriate rotation ratio. But the problem is, due to the layout of the LAMBCHOP and the complicated system of beams and pipes supporting it, the pegs that will support the gears are fixed in place.
# The LAMBCHOP's engineers have given you lists identifying the placement of groups of pegs along various support beams. You need to place a gear on each peg (otherwise the gears will collide with unoccupied pegs). The engineers have plenty of gears in all different sizes stocked up, so you can choose gears of any size, from a radius of 1 on up. Your goal is to build a system where the last gear rotates at twice the rate (in revolutions per minute, or rpm) of the first gear, no matter the direction. Each gear (except the last) touches and turns the
@gggauravgandhi
gggauravgandhi / gfc_l2q1_solution.py
Created June 4, 2017 08:59
Google's Foo.bar chess Knight's Shortest Path Chess Puzzle Solution (Don't Get Volunteered!)
# Quiz : Don't Get Volunteered!
# ======================
# As a henchman on Commander Lambda's space station, you're expected to be resourceful, smart, and a quick thinker. It's not easy building a doomsday device and capturing bunnies at the same time, after all! In order to make sure that everyone working for her is sufficiently quick-witted, Commander Lambda has installed new flooring outside the henchman dormitories. It looks like a chessboard, and every morning and evening you have to solve a new movement puzzle in order to cross the floor. That would be fine if you got to be the rook or the queen, but instead, you have to be the knight. Worse, if you take too much time solving the puzzle, you get "volunteered" as a test subject for the LAMBCHOP doomsday device!
# To help yourself get to and from your bunk every day, write a function called answer(src, dest) which takes in two parameters: the source square, on which you start, and the destination square, which is where you need to land to solve the puz
@gggauravgandhi
gggauravgandhi / XPS-15 9560 Getting Nvidia To Work on KDE Neon
Created February 23, 2018 12:03 — forked from whizzzkid/XPS-15 9560 Getting Nvidia To Work on KDE Neon
[XPS 15 Early 2017 9560 kabylake] Making Nvidia Drivers + (CUDA 8 / CUDA 9 / CUDA 9.1) + Bumblebee work together on linux ( Ubuntu / KDE Neon / Linux Mint / debian )
# Instructions for 4.14 and cuda 9.1
# If upgrading from 4.13 and cuda 9.0
$ sudo apt-get purge --auto-remove libcud*
$ sudo apt-get purge --auto-remove cuda*
$ sudo apt-get purge --auto-remove nvidia*
# also remove the container directory direcotory at /usr/local/cuda-9.0/
# Important libs required with 4.14.x with Cuda 9.X
$ sudo apt install libelf1 libelf-dev
@gggauravgandhi
gggauravgandhi / nginxproxy.md
Created April 11, 2018 08:14 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

#!/bin/bash
# export DBUS_SESSION_BUS_ADDRESS environment variable because cron hates me
PID=$(pgrep -u USER gnome-session-b)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
/usr/bin/gsettings set org.gnome.shell.extensions.user-theme name 'Flat-Plat'
/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Flat-Plat'
/usr/bin/gsettings set org.gnome.desktop.background picture-uri 'file://WALLPAPER-PATH'
/usr/bin/gsettings --schemadir ~/.local/share/gnome-shell/extensions/[email protected] set org.zzrough.gs-extensions.drop-down-terminal background-color 'rgb(69,90,100)'