Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Stewart Park stewartpark

🏠
Working from home
Block or report user

Report or block stewartpark

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stewartpark
stewartpark / chatbot.py
Last active Sep 12, 2019
A very simple/naive chatbot implementation with GPT-2
View chatbot.py
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 Jun 15, 2019
Kubernetes-enabled Drone CI job/namespace cleaner
View README.md

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.

View kill-ns.sh
#!/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 Jun 20, 2018
Quick and dirty Ruby lexer/parser/rewriter to make the rails 5 migration easier
View ruby_migrator.rb
#!/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 Jun 12, 2018
Play with a running ruby process safely
View reval
#!/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
A patch to `node-fetch` to cause random errors
View fetch-random-error.patch
--- 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 Aug 9, 2019
Userspace Early OOM Killer for Kubernetes Nodes
View oom-killer.yml
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: oom-killer
namespace: kube-system
labels:
k8s-app: oom-killer
spec:
selector:
View 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 Feb 17, 2017
Simple CircleCI Build Trigger
View circleci-trigger.sh
# 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
View keybase.md

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:

You can’t perform that action at this time.