Skip to content

Instantly share code, notes, and snippets.

Stephen Merity Smerity

View GitHub Profile
@Smerity
Smerity / send_message
Created Jan 10, 2019
Send a message using the Slack postMessage API
View send_message
import requests
AUTH_TOKEN = 'xoxb-...'
channel = '#locked-out'
USER_ID = 'UDAS0J04S' # A user ID obtained by `list_members.py`
text = f'<@{USER_ID}>, Smerity locked himself out'
params = {
'token': AUTH_TOKEN,
@Smerity
Smerity / list_members.py
Created Jan 10, 2019
List members of a bot's Slack
View list_members.py
import pprint
import requests
AUTH_TOKEN = 'xoxb-...'
params = {'token': AUTH_TOKEN}
r = requests.post('https://slack.com/api/users.list', params=params)
for member in r.json()['members']:
@Smerity
Smerity / post_process.py
Created Nov 19, 2017
WikiText: Python 2 post processing used on Moses tokenized input
View post_process.py
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
number_match_re = re.compile(r'^([0-9]+[,.]?)+$')
number_split_re = re.compile(r'([,.])')
@Smerity
Smerity / failed_logins
Created Jun 6, 2017
List of failed SSH logins produced by `egrep -o "invalid user ([^ ]+?) " /var/log/auth.log | cut -d ' ' -f 3 | sort | uniq -c | sort -nk 1`
View failed_logins
1 .+?
1 [^
2 0000
2 010101
2 1111
2 1234
2 12345
2 666666
2 adm
2 anna
@Smerity
Smerity / cupy-pytorch-ptx.py
Created May 21, 2017 — forked from szagoruyko/cupy-pytorch-ptx.py
CuPy example for PyTorch updated to support Python 3
View cupy-pytorch-ptx.py
import torch
from cupy.cuda import function
from pynvrtc.compiler import Program
from collections import namedtuple
a = torch.randn(1,4,4).cuda()
b = torch.zeros(a.size()).cuda()
kernel = '''
extern "C"
@Smerity
Smerity / count_wikitext.py
Created Feb 9, 2017
Count the number of unique tokens in WikiText-2 and/or WikiText-103
View count_wikitext.py
vocab = set()
for i, line in enumerate(open('wiki.train.tokens')):
words = [x for x in line.split(' ') if x]
[vocab.add(word) for word in words]
if i < 10: print(words)
print('Vocab size:', len(vocab))
@Smerity
Smerity / cartpole.py
Last active May 26, 2017
Script for Cartpole using policy gradient via Chainer, two layer MLP, dropout, and rejection sampling of historical memories
View cartpole.py
''' Script for Cartpole using policy gradient via Chainer, two layer MLP, dropout, and rejection sampling of historical memories '''
import gym
import numpy as np
import chainer
from chainer import optimizers
from chainer import ChainList, Variable
import chainer.functions as F
@Smerity
Smerity / buggy_cartpole.py
Last active Sep 2, 2016
Buggy (but preserved for posterity) script for Cartpole using policy gradient via Chainer, two layer MLP, dropout, and vaguely rejection sampling of historical memories
View buggy_cartpole.py
""" Quick script for Cartpole using policy gradient via Chainer, two layer MLP, dropout, and vaguely rejection sampling of historical memories """
import gym
import numpy as np
import chainer
from chainer import optimizers
from chainer import ChainList, Variable
import chainer.functions as F
@Smerity
Smerity / time_dist.py
Last active Sep 20, 2015
Test the difference between Dense and TimeDistributedDense in Keras
View time_dist.py
from __future__ import print_function
import numpy as np
np.random.seed(1337)
import sys
from keras.utils.test_utils import get_test_data
from keras.models import Sequential
from keras.layers.core import Dense, TimeDistributedDense
from keras.layers.recurrent import GRU
@Smerity
Smerity / babi_rnn.py
Created Aug 17, 2015
Epoch tuning through early stopping for bAbi RNN in Keras
View babi_rnn.py
from __future__ import absolute_import
from __future__ import print_function
from functools import reduce
import re
import tarfile
import numpy as np
np.random.seed(1337) # for reproducibility
bAs such, I agree strongly with you that this won't make a good test dataset for testing various RNN architectures.from keras.callbacks import EarlyStopping
You can’t perform that action at this time.