Skip to content

Instantly share code, notes, and snippets.

View st0le's full-sized avatar

Gaurav Kamath st0le

View GitHub Profile
@st0le
st0le / UbuntuLegit.json
Created August 9, 2019 19:02
UbuntuLegit Windows Terminal Scheme
{
"background": "#2C001E",
"black": "#4E9A06",
"blue": "#3465A4",
"brightBlack": "#555753",
"brightBlue": "#729FCF",
"brightCyan": "#34E2E2",
"brightGreen": "#8AE234",
"brightPurple": "#AD7FA8",
def popcount(n):
c = 0
while n != 0:
c += n % 2
n //= 2
return c
def popcount_range_naive(n):
return sum(map(popcount, range(n + 1)))

Keybase proof

I hereby claim:

  • I am ST0LE on github.
  • I am gauravkamath (https://keybase.io/gauravkamath) on keybase.
  • I have a public key whose fingerprint is AC20 EC1E 4274 DA5F 32E4 4704 B9C9 97B3 05BE A391

To claim this, I am signing this object:

@st0le
st0le / Find-FirstItem.ps1
Last active March 22, 2018 00:57
Simple Utility Function
Function Find-FirstItem {
[CmdletBinding()]
[Alias("ffi")]
param(
[Parameter(Mandatory, Position = 0)]
[ValidateNotNullOrEmpty()]
[string] $Filter
)
Get-ChildItem -Recurse -Filter $Filter | Select-Object -First 1 -ExpandProperty FullName
}
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MyTrayApp
{
public class SysTrayApp : Form
{
[STAThread]
public static void Main()
@st0le
st0le / MediaKeys.ahk
Created November 14, 2017 21:27
Add MediaKey shortcuts to normal keyboard
; ^ = Ctrl
; volume up
^Numpad8::Volume_Up
; volume down
^Numpad2::Volume_Down
; volume mute
^Numpad0::Volume_Mute
@st0le
st0le / autoexec.cfg
Last active July 16, 2017 04:56
autoexec.cfg
alias +jumpthrow "+jump;-attack"
alias -jumpthrow "-jump"
bind mouse3 +jumpthrow
bind mouse5 +voicerecord
alias +fwdjumpthrow "+forward;+jump;-attack"
alias -fwdjumpthrow "-forward;-jump"
bind capslock +fwdjumpthrow
exec buyscript;
alias +djump "+jump; +duck"
alias -djump "-jump; -duck"

Distributed Circular linked list sum

You are given a circular linked list whose nodes are distributed. Every node has next pointer and a method send(integer). A node can talk to its next node only. Different instances of same �threads are running in the nodes. How would you implement the run method of the thread class so that each node prints the sum of complete linked list.


Distributed binary tree sum

You are given a binary tree where each node has an integer value, a left, right and parent pointer. Every node is an independent distributed system where a thread is running in each node. You can talk to other node only by one method called "send(node, data)". And a node can call "send" only to its children or parent. How will you design the system so that all the nodes know the total sum of values of all the nodes in the binary tree and report them asynchronously.


Distributed doubly linked list sum

You are given a doubly linked list whose nodes are distributed. Every node has n

@st0le
st0le / huffman.py
Last active May 19, 2017 00:00
Py3
from collections import Counter
from heapq import heapify, heappop, heappush
s = input()
c = Counter(s)
pq = [(c[k], k, None, None) for k in c]
codes = {}
heapify(pq)
while len(pq) > 1:
r = heappop(pq)
import hashlib, os
unique = dict()
for filename in os.listdir('.'):
if os.path.isfile(filename):
filehash = hashlib.md5(open(filename, 'rb').read()).hexdigest()
if filehash not in unique:
unique[filehash] = filename
else:
print (filename + ' is a duplicate of ' + unique[filehash])