Skip to content

Instantly share code, notes, and snippets.

View keenhenry's full-sized avatar

Henry Huang keenhenry

  • Eindhoven, Noord Brabant, The Netherlands
View GitHub Profile
@keenhenry
keenhenry / mainpython.md
Created September 8, 2019 08:33 — forked from rochacbruno/mainpython.md
Use of __main__.py

The use of __main__.py to create executables

myprojectfolder/
    |_ __main__.py
    |_ __init__.py

Being __main__.py:

print("Hello")

@keenhenry
keenhenry / Count Code lines
Created February 12, 2019 20:41 — forked from amitchhajer/Count Code lines
Count number of code lines in git repository per user
git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*\((.*?)\s*[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n
@keenhenry
keenhenry / deployment-tool-ansible-puppet-chef-salt.md
Created November 23, 2017 20:11 — forked from jaceklaskowski/deployment-tool-ansible-puppet-chef-salt.md
Choosing a deployment tool - ansible vs puppet vs chef vs salt

Requirements

  • no upfront installation/agents on remote/slave machines - ssh should be enough
  • application components should use third-party software, e.g. HDFS, Spark's cluster, deployed separately
  • configuration templating
  • environment requires/asserts, i.e. we need a JVM in a given version before doing deployment
  • deployment process run from Jenkins

Solution

@keenhenry
keenhenry / js-concepts.md
Created October 8, 2017 19:03 — forked from ericelliott/js-concepts.md
Seven JS Concepts You Must Understand Before Your Next Job Interview

Here are seven JavaScript concepts you must understand before you go into your next JavaScript job interview:

  1. Prototypes - JavaScript is a prototype-based language. Even more, it's a delegation-based system, which means that each object has a prototype chain. When you try to access a property on an object, and that property is not found, JavaScript looks at the object's prototype. The prototype is a delegate object, which means that the property lookup is delegated to the prototype object. That object, in turn, may have its own prototype. The search continues up the prototype chain until it reaches the root prototype, which is usually Object.prototype. The best feature of this system is that many object instances can share the same methods on a prototype object, which conserves memory and enables easy code reuse. To assign a prototype to a new object, you can use Object.create(prototypeObject). Prototypal OO is the first course being offered in the "Learn JavaScript" series.

  2. Functional Programming

@keenhenry
keenhenry / trie.py
Last active July 30, 2017 09:05
Python Trie implementation
#!/usr/bin/env python
class Node(object):
__slots__ = ('letters', 'children', 'num_occurs')
def __init__(self, letters=None):
self.letters = letters # only leaf nodes have non-None letters
self.children = {}
@keenhenry
keenhenry / supervisord.sh
Created June 15, 2017 13:35 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@keenhenry
keenhenry / supervisord.conf
Created June 15, 2017 13:28 — forked from CMCDragonkai/supervisord.conf
Upstart: Upstart Init Script for Supervisord
# supervisord - Upstarts the supervisor as service
# Put this file into /etc/init/supervisord.conf
# sudo service supervisord start
# sudo service supervisord stop
# Service gets started as root
# Needs `pgrep` available to root
description "Supervisord - Upstart"
stop on runlevel [016]
@keenhenry
keenhenry / test_runner.py
Created February 17, 2017 09:21
Use file storage on the local filesystem in Django unit tests
import shutil
import tempfile
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db.models import FileField
from django.db.models.loading import get_model, get_models
from django.test.runner import DiscoverRunner
@keenhenry
keenhenry / gist:e3e86c8563808f3fdfdb8687d078c295
Created February 5, 2017 19:40 — forked from rduplain/gist:2149194
PyCon 2012 Digest for WillowTree Apps

PyCon 2012 Digest

from DevOps team {rduplain,mattd,teebes}, to mobile developers at WillowTree Apps

Pronunciation

@keenhenry
keenhenry / array_iteration_thoughts.md
Created January 14, 2017 11:36 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and