no Homebrew required
$ 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
#!/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 |
(defn pascal | |
"Gets the nth row of a pascal triangle." | |
[n] | |
(nth | |
(iterate #(vec (map + (conj % 0) (cons 0 %))) [1N]) | |
(dec n))) | |
; user=> (pascal 10) | |
; [1 9 36 84 126 126 84 36 9 1] |
;; recursive greatest common divisor | |
(defn gcd [a b] | |
(if (zero? b) | |
a | |
(gcd b (mod a b)))) | |
(= 2 (gcd 2 4)) ;; true |
(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))))) |
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)): |
'use strict'; | |
var assert = require('assert'); | |
var log = console.log; | |
// undirected graph | |
function Graph() { | |
this.nodes = []; | |
this.edges = {}; | |
this.dists = {}; |
/** | |
* 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 |
""" | |
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/ | |
""" |
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): |