Skip to content

Instantly share code, notes, and snippets.

View WanderingStar's full-sized avatar

Aneel Nazareth WanderingStar

View GitHub Profile
@WanderingStar
WanderingStar / kylie_said_to_jason.py
Last active September 1, 2023 03:15
Kylie Said To Jason
# For an explanation, see https://www.youtube.com/watch?v=hHbUum0CVbI
import statistics
from random import random
init = []
r = 0
n = 0
setTimeout(() => {
window.close();
}, 5000)
@WanderingStar
WanderingStar / twofivethree.py
Created September 6, 2020 01:35
twofivethree
def print_row(elems):
n = len(elems)
if n % 2 == 0:
prefix = " " * ((22 - n)//2)
else:
prefix = " " + " " * ((21 - n)//2)
print(f"{n:>3} " + prefix + " ".join(elems))
def to_rows(elems):
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 4 columns, instead of 2. in line 1.
date country crossing transit
1980/09/19 India
1980/12/31 United States Guess
1984/02/05 India
1984/05/31 United States Guess
2000/11/14 United Kingdom Heathrow
2000/11/27 Belgium Brussels
2000/11/30 Germany Munich
2000/12/04 Spain Malaga
2000/12/11 Italy Rome
# If there are duplicated keys...
# cogroup returns a tuple of lists of the matching keys
x = sc.parallelize([("a", 1), ("b", 4), ("a", 3)])
y = sc.parallelize([("a", 2), ("a", 5)])
[(x, tuple(map(list, y))) for x, y in sorted(list(x.cogroup(y).filter(lambda x: x[1][0] and x[1][1]).collect()))]
# ==> [('a', ([1, 3], [2, 5]))]
# join returns the cartesian product...
df1 = spark.createDataFrame(rdd1).toDF("id", "val")
df1.createOrReplaceTempView("table1")
df2 = spark.createDataFrame(rdd2).toDF("id", "val")
df2.createOrReplaceTempView("table2")
def callable_ssql_timeit():
query="SELECT * FROM table1 LEFT JOIN table2 ON table1.id=table2.id"
spark.sql(query)
print(timeit.timeit(callable_ssql_timeit, number=100))

Keybase proof

I hereby claim:

  • I am wanderingstar on github.
  • I am wanderingstar (https://keybase.io/wanderingstar) on keybase.
  • I have a public key whose fingerprint is 890E 19AE 3034 099C 54FA 6AEE A745 4AD2 D750 BE3F

To claim this, I am signing this object:

protocol A {}
class B: A {
let v: Int
init(v: Int) { self.v = v }
}
let arr = [B(v: 0), B(v: 1)]
@WanderingStar
WanderingStar / SubclassFactory.swift
Last active March 17, 2016 03:16
Subclass Factory
typealias JSON = [String: AnyObject]
class Shape {
static var subtypes = [String: Shape.Type]()
required init?(json: JSON) {
// base class does nothing
}
static func factory(json: JSON) -> Shape? {
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy2 Experiment Builder (v1.80.03), July 28, 2014, at 16:09
If you publish work using this script please cite the relevant PsychoPy publications
Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13.
Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"""
from __future__ import division # so that 1/3=0.333 instead of 1/3=0