Skip to content

Instantly share code, notes, and snippets.

View hartfordfive's full-sized avatar

Alain L hartfordfive

View GitHub Profile
@hartfordfive
hartfordfive / byte-city-bus-network
Created June 7, 2017 18:49
Programming Test Question
(Originally found at: https://pastebin.com/Lkjad3y6)
The Bus
-----------------
The streets of Byte City form a regular, chessboardlike network - they are either north-south or west-east directed. We shall call them NS- and WE-streets. Furthermore, each street crosses the whole city. Every NS-street intersects every WE- one and vice versa. The NS-streets are numbered from 1 to n, starting from the westernmost. The WE-streets are numbered from 1 to m, beginning with the southernmost. Each intersection of the i-th NS-street with the j-th WE-street is denoted by a pair of numbers (i, j) (for 1 <= i <= n, 1 <= j <= m).
There is a bus line in Byte City, with intersections serving as bus stops. The bus begins its itinerary by the (1, 1) intersection, and finishes by the (n, m) intersection. Moreover, the bus may only travel in the eastern and/or northern direction.
There are passengers awaiting the bus by some of the intersections. The bus driver wants to choose his route in a way that allows him to take as many
@hartfordfive
hartfordfive / term_context.go
Created June 1, 2017 16:48 — forked from matryer/term_context.go
Making Ctrl+C termination cancel the context.Context
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
@hartfordfive
hartfordfive / circularlist.go
Last active January 1, 2023 17:58
Simple Go circular list using the ring package
package main
// Run at: https://play.golang.org/p/waIvysrhXJ
import (
"container/ring"
"fmt"
)
type CircularList struct {
@hartfordfive
hartfordfive / incrementer.go
Created April 9, 2017 00:29
Simple incrementing closure in Go
package main
import (
"fmt"
)
func main() {
incr := incr()
for i := 0; i < 10; i++ {
fmt.Printf("Count: %d\n", incr())
@hartfordfive
hartfordfive / kafka-del-topics.sh
Last active October 30, 2023 04:32
Script to delete all kafka topics on a given cluster
#!/bin/bash
TOPICS=$(kafka-topics --zookeeper [ZK_IP]:2181/kafka --list )
for T in $TOPICS
do
if [ "$T" != "__consumer_offsets" ]; then
kafka-topics --zookeeper [ZK_IP]:2181/kafka --delete --topic $T
fi
done
@hartfordfive
hartfordfive / gist:9fc7422a1af301152c0a9f16ac76839c
Created February 22, 2017 14:22
Removing image metadata and resizing on OSX
# First install exiftool with Brew if you don't already have it
brew install exiftool
# Next, remove all metadata form the image
exiftool -all= [IMAGE_FILENAME]
# Now resize the image
sips -Z [MAX_HEIGHT_AND_WIDTH] [IMAGE_NAME]
@hartfordfive
hartfordfive / gist:159a34322701493700d62f6852d4dc5d
Created February 16, 2017 19:01
Creating a local encrypted database for your TestKitcheCI suites
# Once
chef exec gem install knife-solo_data_bag
# Then run this to create the databag
chef exec knife solo data bag create [BAG_NAME] [ITEM_NAME] --secret-file '[PATH_TO_SECRET]' --data-bag-path test/integration/default/data_bags/
@hartfordfive
hartfordfive / reindex.sh
Last active June 24, 2025 23:53
Bash script to re-index all indices matching apattern from a remote Elasticsearch cluster to a local one
#!/bin/bash
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo "Usage: ./reindex.sh [REMOTE_HOST:REMOTE_PORT] [INDEX_PATTERN] [LOCAL_HOST:LOCAL_PORT]"
exit 1
fi
REMOTE_HOST=$1
PATTERN=$2
if [ "$3" == "" ]; then
### Keybase proof
I hereby claim:
* I am hartfordfive on github.
* I am hartfordfive (https://keybase.io/hartfordfive) on keybase.
* I have a public key ASCs9zG687c1KzH-HLDL9Z6lZ6_fHXxOhsswK9_XYb19TQo
To claim this, I am signing this object:
@hartfordfive
hartfordfive / cloudera-streamsets-csd.sh
Created February 8, 2017 11:21
Downloads the CSD package for StreamSets 2.3.0 on Clouder Manager (CDH 5.10)
#!/bin/bash
yum install -y wget
wget https://archives.streamsets.com/datacollector/2.3.0.0/csd/STREAMSETS-2.3.0.0.jar
mv STREAMSETS-2.3.0.0.jar /opt/cloudera/csd/
chown cloudera-scm:cloudera-scm STREAMSETS-2.3.0.0.jar
chmod 775 STREAMSETS-2.3.0.0.jar
/etc/init.d/cloudera-scm-server restart