Skip to content

Instantly share code, notes, and snippets.

View stewartpark's full-sized avatar
🏠
Working from home

Stewart Park stewartpark

🏠
Working from home
View GitHub Profile
#!/usr/bin/env python
# This is an example Git server. http://blog.nerds.kr/post/106956608369/implementing-a-git-http-server-in-python
# Stewart Park <stewartpark92@gmail.com>
from flask import Flask, make_response, request, abort
from StringIO import StringIO
from dulwich.pack import PackStreamReader
import subprocess, os.path
from flask.ext.httpauth import HTTPBasicAuth
@stewartpark
stewartpark / oom-killer.yml
Last active April 21, 2023 23:04
Userspace Early OOM Killer for Kubernetes Nodes
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: oom-killer
namespace: kube-system
labels:
k8s-app: oom-killer
spec:
selector:
@stewartpark
stewartpark / xor.py
Created October 12, 2015 08:17
Simple XOR learning with keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD
import numpy as np
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[1],[1],[0]])
model = Sequential()
model.add(Dense(8, input_dim=2))
@stewartpark
stewartpark / chatbot.py
Last active September 12, 2019 07:20
A very simple/naive chatbot implementation with GPT-2
import gpt_2_simple as gpt2
import os
# model_name = '124M'
# model_name = '355M'
model_name = '774M'
if not os.path.exists('models/' + model_name):
gpt2.download_gpt2(model_name=model_name)

Keybase proof

I hereby claim:

  • I am stewartpark on github.
  • I am stewartpark (https://keybase.io/stewartpark) on keybase.
  • I have a public key ASAmU77qRuCUZm4za1N7322wqNYO3bVH97qH-8PeDCueIgo

To claim this, I am signing this object:

@stewartpark
stewartpark / README.md
Created June 15, 2019 23:29
Kubernetes-enabled Drone CI job/namespace cleaner

Kubernetes-enabled Drone CI currently has two problems.

  1. Cleaning up jobs is dependent on TTL, which is not enabled by default in most Kubernetes clusters.
  1. For each app's pipelines, it creates a namespace. Which is really nice, but sometimes it creates forever terminating namespaces.

You also have to give it the right authorization on a RBAC-enabled cluster. I don't recommend using this on a production cluster. Probably waiting for Drone CI to mature is a better idea.

#!/bin/bash
###############################################################################
# Copyright (c) 2018 Red Hat Inc
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
@stewartpark
stewartpark / ruby_migrator.rb
Created June 20, 2018 19:23
Quick and dirty Ruby lexer/parser/rewriter to make the rails 5 migration easier
#!/usr/bin/env ruby
##
# Quick and dirty ruby lexer
class RubyLexer
TOKENS = {
identifier: /\A[@a-zA-Z_][a-zA-Z_0-9]*/m,
symbol: /\A:[a-zA-Z0-9_]+/m,
string: /\A"([^"]|\\.)*"|\A'([^']|\\.)*'/,
shellout_literal: /\A`([^`\\]|\\.)*`/m,
@stewartpark
stewartpark / reval
Last active June 12, 2018 19:24
Play with a running ruby process safely
#!/usr/bin/env bash
#
# ./reval "pid" "ruby code"
rm /tmp/ruby.out 2> /dev/null
expr=$(echo $2 | base64)
(
echo "set breakpoint pending on";
echo "tb rb_funcallv"
echo "commands"
@stewartpark
stewartpark / fetch-random-error.patch
Created May 23, 2018 20:52
A patch to `node-fetch` to cause random errors
--- node_modules/node-fetch/lib/index.js 2018-03-25 13:54:59.000000000 -0700
+++ node_modules/node-fetch/lib/index.patched.js 2018-05-23 13:51:07.000000000 -0700
@@ -249,6 +249,9 @@
return consumeBody.call(this).then(function (buffer) {
try {
+ if(Math.random() < 0.1) {
+ return Body.Promise.reject(new FetchError('random error raised as a test'));
+ }
return JSON.parse(buffer.toString());