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
@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)
@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());
@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 / setup-gcloud.sh
Last active May 31, 2017 05:15
setup-gcloud.sh
#!/bin/sh
# This script is to set up Google Cloud in CircleCI
# Author: Stewart Park <hello@stewartjpark.com>
#
# Usage:
# (set up GCLOUD_SERVICE_KEY as a base64-encoded json credentials file, GCLOUD_PROJECT_ID as your project ID)
# curl -L https://goo.gl/6pDHc6 | bash
sudo -E env "PATH=$PATH" gcloud --quiet components update
sudo chmod 757 /home/ubuntu/.config/gcloud/logs -R
@stewartpark
stewartpark / circleci-trigger.sh
Last active February 17, 2017 19:18
Simple CircleCI Build Trigger
# This script is to trigger another CircleCI build inside a CircleCI build easily
# Author: Stewart Park <hello@stewartjpark.com>
#
# Usage:
# curl -L https://goo.gl/qU14Wd | PROJECT=username/repo-name API_TOKEN=create-one-on-circleci-config bash
set -e
# Install dependencies
sudo apt-get install jq

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: