Skip to content

Instantly share code, notes, and snippets.

@dpapathanasiou
dpapathanasiou / RidePATH.md
Created January 18, 2025 21:21
This is a simple way of using the real time json format feed from the Port Authority Trans-Hudson (PATH) rail system to get a list of when the next trains are arriving per station.

This is a simple way of using the real time json format feed from the Port Authority Trans-Hudson (PATH) rail system to get a list of when the next trains are arriving per station.

This gist uses both curl and jq, which are typically pre-installed on most computers.

curl -s https://www.panynj.gov/bin/portauthority/ridepath.json | \
jq -r \
--arg STATION "HOB" \
'.results[] | select (.consideredStation == $STATION) | .destinations[] | .messages[] | (.arrivalTimeMessage | (" " * (8 - length)) +.)  + " => " + .headSign' 
@dpapathanasiou
dpapathanasiou / reformat_csv.py
Last active April 21, 2022 22:48
A simple python script to reduce or reformat a csv file, producing a csv with a specific sub-set of columns, stripping out any undesired characters from the individual row values
'''
A simple python script to reduce or reformat a csv file, producing a
csv with a specific sub-set of columns, stripping out any undesired
characters from the individual row values.
'''
import csv
@dpapathanasiou
dpapathanasiou / simple_kv_service.py
Created December 2, 2020 22:50
A simple example of a key-value (kv) storage and lookup service, accessible over http/rest
#!/usr/bin/env python3
"""
simple_kv_service.py
A simple example of a key-value (kv) storage and lookup service,
accessible over http/rest:
http://[host]:[port]/set?somekey=somevalue => assigns "somevalue" to "somekey"
http://[host]:[port]/get?key=somekey => looks up "somekey" and returns its value, if it exists
@dpapathanasiou
dpapathanasiou / .bash_aliases
Created March 15, 2020 14:27
Scripting the pdftk-java jar to work like the pdftk binary
alias pdftk='$HOME/.pdftk.sh'
#!/usr/bin/env python
"""
A breadth-first search implementation from:
"MIT Open CourseWare: Introduction to Algorithms"
Lecture 13: Breadth-First Search
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/lecture-13-breadth-first-search-bfs/
@dpapathanasiou
dpapathanasiou / depth_first_search.py
Created April 20, 2019 20:26
Depth-First Search
#!/usr/bin/env python
"""
An iterative implementation of depth-first search from:
"Python Algorithms: Mastering Basic Algorithms in the Python Language"
by Magnus Lie Hetland
ISBN: 9781484200551
#!/usr/bin/env python
"""
An implementation of the "sliding window" technique to find shortest matching subarrays, inspired by:
https://leetcode.com/problems/find-all-anagrams-in-a-string/discuss/92007/sliding-window-algorithm-template-to-solve-all-the-leetcode-substring-search-problem
"""
from sys import maxint
@dpapathanasiou
dpapathanasiou / bellman_ford.py
Created April 20, 2019 20:23
Bellman Ford Algorithm
#!/usr/bin/env python
"""
An implementation of the Bellman-Form algorithm from:
"Python Algorithms: Mastering Basic Algorithms in the Python Language"
by Magnus Lie Hetland
ISBN: 9781484200551
@dpapathanasiou
dpapathanasiou / breadth_first_search.py
Created April 2, 2019 23:13
Breadth-First Search in Python
#!/usr/bin/env python
"""
A breadth-first search implementation from:
"Python Algorithms: Mastering Basic Algorithms in the Python Language"
by Magnus Lie Hetland
ISBN: 9781484200551
@dpapathanasiou
dpapathanasiou / quicksort.py
Created March 25, 2019 01:02
Quicksort in Python
#!/usr/bin/env python
"""
An implementation in python, inspired by the version in "Learn You
a Haskell for Great Good!"
(http://learnyouahaskell.com/recursion#quick-sort)
"""
def quicksort (a):