Skip to content

Instantly share code, notes, and snippets.

View remoharsono's full-sized avatar

Remo Harsono remoharsono

View GitHub Profile
@remoharsono
remoharsono / tests.py
Created July 31, 2018 09:52 — forked from magopian/tests.py
Unit test to validate django templates
class TemplatesTest(TestCase):
def test_templates(self):
"""Templates can compile properly and there's no mismatched tags"""
# get app template dirs
template_dirs = []
apps = [app for app in settings.INSTALLED_APPS
if app.startswith('rh2')]
for app in apps:
mod = import_module(app)
@remoharsono
remoharsono / 1_kubernetes_on_macOS.md
Created August 4, 2018 19:10 — forked from kevin-smets/1_kubernetes_on_macOS.md
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

@remoharsono
remoharsono / allow_tags.py
Created August 15, 2018 06:10 — forked from mhulse/allow_tags.py
[Django 1.3] Template tag that allows Django tags in variables (i.e. flatpage content).
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
# http://www.soyoucode.com/2011/set-variable-django-template
# http://djangosnippets.org/snippets/861/
# http://stackoverflow.com/questions/4183252/what-django-resolve-variable-do-template-variable
# https://docs.djangoproject.com/en/dev/ref/templates/api/
@remoharsono
remoharsono / gist:a667f11da73eb2b88798529b2f6bf396
Created September 13, 2018 03:06 — forked from darkpixel/gist:3473470
Don't lose model association with a Session object when logging in
def cycle_key(self):
#TODO: Errors here will tank the system, probably need some better handling...
old_session_key = self.session_key
old_session = Session.objects.get(session_key=old_session_key)
try:
cart = Cart.objects.get(session=old_session)
super(SessionStore, self).cycle_key()
new_session_key = self.session_key
new_session = Session.objects.get(session_key=new_session_key)
cart.session = new_session
@remoharsono
remoharsono / r_python_homebrew.sh
Created October 9, 2018 14:08 — forked from pachadotdev/r_python_homebrew.sh
Install R and Python via Homebrew
# See http://pacha.hk/2017-07-12_r_and_python_via_homebrew.html
# XCode CLT
xcode-select --install
# Update Homebrew and add formulae
brew update
# Check for broken dependencies and/or outdated packages
brew doctor
@remoharsono
remoharsono / gist:43c07cc7674d2eff9b21102cbf1a8297
Created October 17, 2018 12:02 — forked from evildmp/gist:3094281
Set up Django, nginx and uwsgi

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

@remoharsono
remoharsono / kmp_match.php
Created November 26, 2018 00:12 — forked from white-gecko/kmp_match.php
Knuth-Morris-Pratt-Algorithm
<?php
/**
* This is an implementation of the Knuth-Morris-Pratt-Algorithm as in
* Thomas H. Cormen et. al.: "Algorithmen - Eine Einführung"
* (German version by Paul Molitor) 3. Auflage, page 1017
*
* My changes:
* - Indexes starting with 0
* - overlapping matches are recognized
*/
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)
@remoharsono
remoharsono / KMP_algo.py
Created November 26, 2018 02:19 — forked from RaphaelAslanian/KMP_algo.py
Implementation of the Knuth-Morris-Pratt algorithm
"""
This module contains an implementation of the Knuth-Morris-Pratt algorithm allowing to look for sequence matching.
For example if you want to find the sequence [1, 2, 3] in [2, 3, 1, 2, 3, 5, 6], you could do:
find_sequence([2, 3, 1, 2, 3, 5, 6], [1, 2, 3])
This algorithm is especially interesting in case of many partial matches. Otherwise, you could simply use a brute
force search with correct performances.
The main function to use here is find_sequence which actually performs the KMP algorithm.
@remoharsono
remoharsono / php-Knuth-Morris.php
Created November 26, 2018 02:20 — forked from fatkulnurk/php-Knuth-Morris.php
Algoritma Knuth-Morris-Pratt
<?php
// Referensi :
// https://id.wikipedia.org/wiki/Algoritma_Knuth-Morris-Pratt
// https://stackoverflow.com/questions/44081348/is-it-possible-to-use-knuth-morris-pratt-algorithm-for-string-matching-on-text-t
// http://www.elangsakti.com/2013/03/implementasi-algoritma-string-matching.html
// https://stackoverflow.com/questions/29439930/knuth-morris-pratt-string-search-algorithm
// https://stackoverflow.com/questions/5873935/how-to-optimize-knuth-morris-pratt-string-matching-algorithm
// https://stackoverflow.com/questions/13271856/understanding-knuth-morris-pratt-algorithm
//
//