Skip to content

Instantly share code, notes, and snippets.

@waprin
waprin / cat_literals.py
Created August 6, 2014 18:47
Concatenate Multi-Line Java String Literals
import fileinput
x = ""
for line in fileinput.input():
x += line
s = ""
i = 1
while i < len(x):
if x[i] == '"':
i += 1
@waprin
waprin / gist:7aee67aefd7530d3587a
Last active June 21, 2018 15:29
Verify Splunk Regex Matches Against Your Entire Log File
#!/usr/bin/env python
# usage ./verify_splunk_coverage.py <log_file>
# set these from splunk-apps/apps/<service-name>/default/props.conf
BREAK_ONLY_BEFORE_REGEX=r'^\d\d:\d\d:\d\d\s\[[^\]]+\]'
EXTRACT_REGEX=r'^\d?\d:\d\d:\d\d\s\[(?P<thread>[^\]]+)\]\s\[(?P<loglevel>\w+)\]\s\[(?P<class>[^\]]+)\]\s\[(?P<username>[^\]]*)\](?P<message>.*)$'
import re,sys
f = open(sys.argv[1])
# Normal person mode
def next_server_number(l):
if len(l) < 1:
return 1
for i in xrange(1, max(l)):
if i not in l:
return i
return max(l) + 1
CACHES = {
‘default’: {
‘BACKEND’: ‘redis_cache.RedisCache’,
‘LOCATION’: [
‘%s:%s’ % (os.getenv(‘REDIS_MASTER_SERVICE_HOST’, ‘127.0.0.1’),
@waprin
waprin / k8s-workshops.html
Last active May 23, 2017 22:19 — forked from ryanj/k8s-workshops.html
http://bit.ly/k8s-workshops: a modular workshop series for learning Kubernetes
<section>
<section id="a-modular-workshop-series-for-learning-kubernetes">
<h2><code>k8s-workshops</code></h2>
<p><a href="http://kubernetes.io/"><img src="https://pbs.twimg.com/profile_images/511909265720614913/21_d3cvM.png" alt="kubernetes" style='width:30%;'></a><br/>a modular workshop series for <a href="http://kubernetes.io/">Kubernetes</a></p>
<h3 class='fragment grow'><a href="http://bit.ly/k8s-workshops"><code>bit.ly/k8s-workshops</code></a></h3>
</section>
<section id='presented-by' data-markdown>
presented by
[![CoreOS Logo](http://i.imgur.com/DRm4KEq.png "")](https://coreos.com)
<section>
<section id="kubernetes-cli-basics-with-kubectl">
<h2>Google Container Engine (GKE) Basics</h2>
<p><a href="http://kubernetes.io/"><img src="https://pbs.twimg.com/profile_images/511909265720614913/21_d3cvM.png" alt="kubernetes" style='width:30%;'></a><br/>with <a href="https://kubernetes.io/docs/user-guide/kubectl/"><code>kubectl</code></a></p>
<h4 class='fragment grow'><a href="http://bit.ly/k8s-kubectl"><code>bit.ly/k8s-kubectl</code></a></h4>
</section>
<section id='presented-by' data-markdown>
presented by
[![CoreOS Logo](http://i.imgur.com/DRm4KEq.png "")](https://coreos.com)
@waprin
waprin / load_matches.py
Created August 12, 2018 23:21
loading dota matches
import json
import time
import requests
input_file = open('liquid_matches.json')
matches = json.load(input_file)
input_file.close()
print('Loading {} matches\n'.format(len(matches)))
f = open('liquid_match_data.txt', 'w')
@waprin
waprin / analyze.py
Created August 12, 2018 23:27
process the liquid matches
class Match:
def __init__(self, match, liquid_win):
self.match = match
self.liquid_win=liquid_win
self.liquid_picks = []
self.liquid_bans = []
self.opponent_picks = []
self.opponent_bans = []
@waprin
waprin / analyze.py
Created August 13, 2018 16:28
High level stats
won_matches = list(filter(lambda m : m.liquid_win, processed_matches))
print('Liquid won {} of the games.'.format(len(won_matches)))
wisp_banned = list(filter(lambda m: 'Io'in m.opponent_bans, processed_matches))
wisp_matches = list(filter(lambda m: 'Io' in m.liquid_picks, processed_matches))
print('Found {} out of {} games where Liquid picked Io.'.format(len(wisp_matches), len(processed_matches)))
print('Io was banned in {} matches.', len(wisp_banned))
@waprin
waprin / analyze.py
Last active August 13, 2018 16:31
Create match class
class Match:
def __init__(self, match, liquid_win):
self.match = match
self.liquid_win=liquid_win
self.liquid_picks = []
self.liquid_bans = []
self.opponent_picks = []
self.opponent_bans = []