Skip to content

Instantly share code, notes, and snippets.

View manju4ever's full-sized avatar
🙏
Namaste !

Manjunath D manju4ever

🙏
Namaste !
View GitHub Profile
@manju4ever
manju4ever / parallel_sort.go
Created August 4, 2020 10:38
Sorting using go routines (split evenly)
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
@manju4ever
manju4ever / race.go
Created August 3, 2020 10:13
Race condition in go - The simple way
package main
/*
Race Condition - The condition occurs when two or more operations try to execute
simultaneously resulting in undeterministic output(s).
*/
func inc(x *int) {
@manju4ever
manju4ever / routine.go
Created August 2, 2020 11:38
Go routines - Simple Example
package main
import (
"fmt"
"sync"
)
func doSomething(wg *sync.WaitGroup, tsk int, args ...string) {
defer wg.Done()
fmt.Printf("\n---- From Thread %d ----- \n", tsk)
@manju4ever
manju4ever / sort.go
Created July 26, 2020 18:21
Sort till you quit in Go
package main
import (
"fmt"
"os"
"sort"
"strconv"
)
func main() {
@manju4ever
manju4ever / potential_friends.js
Last active September 9, 2019 15:05
A simple graph based app - Like in Linkedin and Facebook
// A simple graph based app - Like in Linkedin and Facebook
const social_network = [{
id: 1,
name: "manju",
friends: [2, 4]
}, {
id: 2,
name: 'siddu',
friends: [1, 5],
@manju4ever
manju4ever / linked_list.js
Created September 9, 2019 10:46
Classic Linked list written using ES6
class Node {
constructor(val, next = null) {
this.val = val;
this.next = next;
}
};
class List {
constructor(list) {
@manju4ever
manju4ever / subset.js
Created September 1, 2019 21:23
Find all possible subset pairs in P for a given value S
/**
* Subset Pairs - fp style
* P = numbers, S = sumRequired
* subSetPairs - returns all possible unique pairs
*/
const subSetPairs = (numbers, sumRequired) => {
return numbers.map((num, idx) => [
numbers[idx],
...numbers.slice(0, idx),
...numbers.slice(idx + 1, numbers.length)
gzip on;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component application/x-javascript text/xml application/octet-stream;
gzip_proxied expired no-cache no-store private auth;
client_max_body_size 0;
underscores_in_headers on;
limit_req_zone $binary_remote_addr zone=uploadlimit:10m rate=3r/s;
@manju4ever
manju4ever / dijkstras.js
Last active December 18, 2018 11:23
Dijkstras in JS O(n^2)
const G = [
[Infinity, 3,Infinity],
[3, Infinity, 6],
[Infinity, 6, Infinity],
];
const dijkstras = (G, start) => {
let N = G.length;
let visited = new Array(N).fill(false, 0, N);
let route = new Array(N).fill(start, 0, N);
@manju4ever
manju4ever / quick_sort_with_bin_search.js
Last active December 18, 2018 11:23
Binary Search and Quick Sort with ES6
const quicksort = (arr) => {
if(arr.length < 2) return arr;
const pivotIndex = Math.floor(arr.length / 2);
const pivot = arr[pivotIndex];
let less = [];
let more = [];
for(let i=0; i < arr.length; i++) {
if(i!=pivotIndex) arr[i] >= pivot ? more.push(arr[i]) : less.push(arr[i]);
}
return [