Skip to content

Instantly share code, notes, and snippets.

Trevor L landau

Block or report user

Report or block landau

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@landau
landau / run-solr5.sh
Created Jan 19, 2018
Run Solr5 Example
View run-solr5.sh
#!/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 / pascal.clj
Last active Aug 29, 2015
Gets the nth row of Pascal
View pascal.clj
(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]
View gcd.clj
;; recursive greatest common divisor
(defn gcd [a b]
(if (zero? b)
a
(gcd b (mod a b))))
(= 2 (gcd 2 4)) ;; true
View coins.clj
(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 Oct 3, 2013
Get the k smallest ints from an array.
View ksmallest.py
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)):
View dijkstra.js
'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 Dec 23, 2015
Longest interval in random array
View longest_interval.js
/**
* 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 Sep 24, 2013
Initial filthy solution - need to ditch some shit....
View wordsearch.py
"""
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 Dec 23, 2015
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
View bin_tree.py
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):
@landau
landau / is_circular.py
Last active Dec 23, 2015
Circular Array
View is_circular.py
def is_circular(arr, start):
if not isinstance(arr, list): raise TypeError('Expected arr to be list')
if not isinstance(start, int): raise TypeError('Expected start to be int')
size = len(arr)
n = size
pos = start
# key running count to track that each index is hit
# use the index as the count, total_exp will be the
You can’t perform that action at this time.