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 / 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
@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:
kind: Template
apiVersion: v1
template: oshinko
metadata:
name: oshinko
objects:
- kind: Service
apiVersion: v1
metadata:
package org.apache.hadoop.fs.glusterfs;
import java.net.URI;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.nio.channels.FileLock;
@mattf
mattf / gettrustedglusterfspathinfo.c
Created February 11, 2013 13:49
Tool to get the trusted.glusterfs.pathinfo extended attribute from a file
/*
* Allow retrieval of ONLY the trusted.glusterfs.pathinfo extended
* attribute on a file.
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>