Skip to content

Instantly share code, notes, and snippets.

@shivamMg
shivamMg / command
Created November 1, 2019 18:23
webots arch linux coredump
[shivam@smg ~]$ webots
Fontconfig warning: FcPattern object weight does not accept value [40 210)
/snap/webots/12/usr/share/webots/webots: line 69: 89715 Segmentation fault (core dumped) "$webots_home/bin/webots-bin" "$@"
@shivamMg
shivamMg / gazebo9-ubuntu-xenial.yaml
Last active October 16, 2019 12:29
gazebo9 for ubuntu xenial
gazebo:
ubuntu:
xenial: [gazebo9]
gazebo_ros:
ubuntu:
xenial: [ros-kinetic-gazebo9-ros]
@shivamMg
shivamMg / curry.go
Created January 5, 2019 13:30
Currying
package main
type VarSum func(a ...int) interface{}
func curry(fn func(x, y, z int) int, args ...int) interface{} {
if len(args) >= 3 {
return fn(args[0], args[1], args[2])
}
return VarSum(func(more ...int) interface{} {
args = append(args, more...)
@shivamMg
shivamMg / grammar.txt
Created November 18, 2018 09:39
EBNF for domain names (copied from https://www.ietf.org/rfc/rfc1035.txt)
<domain> ::= <subdomain> | " "
<subdomain> ::= <label> | <subdomain> "." <label>
<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
<let-dig-hyp> ::= <let-dig> | "-"
@shivamMg
shivamMg / gist:b60885fea0cf657d82cbb6e820981d7b
Last active November 6, 2018 10:19
Grammars for parsing arithmetic expressions
Grammar with left-recursion (e.g. Expr's derivation contains Expr as first non-terminal).
Not suitable for Recursive Descent parsing.
Expr = Expr "+" Term | Expr "-" Term | Term
Term = Term "*" Factor | Term "/" Factor | Factor
Factor = "(" Expr ")" | "-" Factor | Number
@shivamMg
shivamMg / git-bisect.sh
Last active September 4, 2018 09:26
git bisect
git clone github.com/go-openapi/spec && cd spec
# we need to know what commit was `PathLoader` added to the `spec` pkg
git bisect start --term-old not-defined --term-new defined
git bisect not-defined cb9ba12 # first commit
git bisect defined master
git bisect run isdefined.sh
@shivamMg
shivamMg / binary_search.py
Last active February 13, 2022 07:15
Popular algorithms
def binary_search(arr, start, end, target):
if start > end:
# target does not exist in arr
return start # index of the next greater element than target
mid = (start + end) // 2
if arr[mid] == target:
return mid
if arr[mid] > target:
return binary_search(arr, start, mid-1, target)
return binary_search(arr, mid+1, end, target)
@shivamMg
shivamMg / bellman-ford.py
Last active May 1, 2018 11:35
Graph Theory
class GraphBellmanFord(Graph):
def bellman_ford(self, src: str):
dist = {}
for _, u in self.V.items():
dist[u] = float('Inf')
src = self.V[src]
dist[src] = 0
edges = []
for e in self.E.values():
@shivamMg
shivamMg / counting-sort.py
Last active April 20, 2018 13:40
Sorting Algorithms
# Total possible values in array
# Array can only be sorted if it's in range [0, K)
K = 10
def counting_sort(arr):
counter = [0 for _ in range(K)]
for a in arr:
counter[a] += 1
@shivamMg
shivamMg / min-heap.py
Last active April 1, 2022 04:43
Data Structures
class MinHeap:
"""A min-heap using an array"""
# storing tree in level-order
arr = []
@staticmethod
def parent(i): return (i - 1) // 2
@staticmethod
def children(i): return (2*i + 1, 2*i + 2)
def insert(self, a):