Skip to content

Instantly share code, notes, and snippets.

@landau
landau / install_nginx_macos_source.md
Created November 25, 2020 13:09 — forked from beatfactor/install_nginx_macos_source.md
Install Nginx on Mac OS from source (without brew)

Install Nginx on Mac OS from source

no Homebrew required

1. Download Nginx

$ cd /usr/local/src
$ curl -OL http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -xvzf nginx-1.12.2.tar.gz && rm nginx-1.12.2.tar.gz
@landau
landau / hashmap.py
Created August 17, 2013 23:39
Hashmap in python
class Hashmap(object):
"""
character holding hash map
"""
def __init__(self, hash_fn, length=100):
assert hasattr(hash_fn, '__call__'), 'You must provide a hash function'
self._buckets = [None] * length
self.hash_len = length
self.hash_fn = hash_fn
@landau
landau / run-solr5.sh
Created January 19, 2018 12:02
Run Solr5 Example
#!/usr/bin/env bash
#####################################################
# This script is compatible with SOLR 5|6.x only
#####################################################
SOLR_PORT=${SOLR_PORT:-8983}
SOLR_VERSION=${SOLR_VERSION:-5.3.1}
version=$SOLR_VERSION
@landau
landau / tree.py
Created June 28, 2013 14:33
Lowest Common Ancestor in Python
class Node(object):
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def __lt__(self, val):
return self.val < val
def __gt__(self, val):
@landau
landau / coins.clj
Last active December 29, 2015 02:39
Coins
(defn count-change [money coins]
(cond
(= money 0) 1
(or (< money 0) (empty? coins)) 0
:else (+
(count-change (- money (first coins)) coins)
(count-change money (rest coins)))))
@landau
landau / ksmallest.py
Created October 3, 2013 19:24
Get the k smallest ints from an array.
import heapq
def heappush(heap, val):
heapq.heappush(heap, -val)
def heappop(heap):
return -heapq.heappop(heap)
def heapify(arr):
for i in xrange(len(arr)):
@landau
landau / dijkstra.js
Created September 26, 2013 01:50
dijkstra
'use strict';
var assert = require('assert');
var log = console.log;
// undirected graph
function Graph() {
this.nodes = [];
this.edges = {};
this.dists = {};
@landau
landau / longest_interval.js
Last active December 23, 2015 21:09
Longest interval in random array
/**
* Longest interval in an array
* Implemented with that graph algo BFS
* [1, 3, 7, 4, 2, 10, 8] should ouput [1, 4]
**/
'use strict';
var log = console.log;
// Builds a undirected graph based on an interval value
@landau
landau / wordsearch.py
Created September 24, 2013 00:42
Initial filthy solution - need to ditch some shit....
"""
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell,
where adjacent cells are those horizontally or vertically neighboring.
The same letter cell may not be used more than once.
input: ASADB, ABCCED
https://www.codeeval.com/open_challenges/65/
"""
@landau
landau / bin_tree.py
Last active December 23, 2015 16:39
Many methods of binary trees. Most built recursively. Tests too! Methods need to be extracted into own test classes. has_children is also inefficient at this moment. It should track as insertions and deletions come along
class Node(object):
def __init__(self, key, parent=None):
self.key = key
self.parent = parent
self.left = None
self.right = None
def has_children(self): return len(self) > 0
def delete(self, node):