Skip to content

Instantly share code, notes, and snippets.

@mattf
mattf / data.py
Last active March 24, 2021 23:04
from pyspark.sql.types import *
from pyspark.sql.functions import mean
with open("data.csv", "w") as fp:
fp.write("""
a,
b,1
c,
d,1
""")
@mattf
mattf / data.csv
Last active March 24, 2021 22:55
a
b 1
c
d 1
def numDecodings(s: str) -> int:
if(not s):return 1
elif(len(s)==1):
if(s=="0"):return 0
else:return 1
if(s[0]=="0"):return 0
prev=1
cur=0 if s[1]=="0" else 1
if(int(s[:2])<=26): cur+=1
@mattf
mattf / shell-pi-test.py
Created April 28, 2017 19:56
shell pi test, pyspark
import random
def inside(p):
x, y = random.random(), random.random()
return x*x + y*y < 1
count = spark.sparkContext.parallelize(xrange(0, 100000000)).filter(inside).count()
print "Pi is roughly %f" % (4.0 * count / 100000000)
: Start up an OpenShift Origin cluster locally
oc cluster up
: Install Oshinko components
oc create -f http://radanalytics.io/resources.yaml
: Install Apache Kafka for OpenShift components
oc create -f https://raw.githubusercontent.com/mattf/openshift-kafka/master/resources.yaml
: Launch an Apache Kafka instance, it is 1-pod, not replicated, not persistent, just-enough kafka
@mattf
mattf / oshinko.app
Last active January 24, 2017 23:06
kind: Template
apiVersion: v1
template: oshinko
metadata:
name: oshinko
objects:
- kind: ServiceAccount
apiVersion: v1
metadata:
@mattf
mattf / graaftel.txt
Last active January 24, 2017 23:12
: Start up an OpenShift Origin cluster locally
oc cluster up
: Launch Oshinko in the current project
oc new-app -f http://goo.gl/ZU02P4
: Authorize Oshinko to write to the OpenShift API
oc policy add-role-to-user edit -z oshinko
: Anayltical application demo - counting words by Joyce
: joyce writes text to a socket
kind: Template
apiVersion: v1
template: oshinko
metadata:
name: oshinko
objects:
- kind: Service
apiVersion: v1
metadata:
@mattf
mattf / kubelet_hostname
Created February 19, 2015 15:04
fake hostname for running kubelet with asymmetric name resolution
#!/bin/sh
# mv /bin/hostname /bin/hostname.real
# install $0 as /bin/hostname (a+rx)
TARGET="kubelet"
IFACE=eth0
PARENT=$(ps -oucmd= $PPID)
@mattf
mattf / gist:10578722
Last active August 29, 2015 13:59
sahara bigpetstore script
create node group
- master
- namenode, oozie, resourcemanager, historyserver
create node group
- worker
- datanode, nodemanager
create cluster
- master: 1