Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Dsouza jasonrdsouza

View GitHub Profile
View ShrinkingSerializedDataWithCompression.md

Background

Rob Heaton wrote a post about shrinking serialized data as part of his excellent PFAB series, and while he talked about a variety of tricks for making the serialization format itself more space efficient, he left out the easiest optimization trick in the book... compression. (It should be noted that he's been splitting up his thoughts on the particular program under analysis across a few posts, so it very well may be the case that he's just saving compression for a later post)

Regardless, I wanted to use his current analysis as a jumping of point to run a quick test and see how various compression algorithms stacked up in terms of space savings.

Generate RGB Map

Python session to gen

@jasonrdsouza
jasonrdsouza / island_counter.py
Created Apr 24, 2020
Snippet to count contiguous islands in a grid
View island_counter.py
from collections import namedtuple
Node = namedtuple('Node', 'row col')
class IslandCounter:
def __init__(self, ocean_map):
self.map = ocean_map
self.max_row = len(ocean_map)
self.max_col = len(ocean_map[0])
@jasonrdsouza
jasonrdsouza / choose_winner.dart
Last active Jun 9, 2020
Dartpad Gist to Choose a Random Winner
View choose_winner.dart
import 'dart:math';
List<String> contestants = [
'Jason',
'Matt',
'Gabe',
'Ishan',
'Luis',
'Katie',
'Andrew',
@jasonrdsouza
jasonrdsouza / nest_thermostat_info.py
Created Jan 4, 2019
Snippet to pull thermostat info from the Nest API
View nest_thermostat_info.py
import nest # https://pypi.org/project/python-nest/
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
napi = nest.Nest(client_id=config['NEST']['client_id'], client_secret=config['NEST']['client_secret'], access_token_cache_file='token_cache')
if napi.authorization_required:
print('Go to ' + napi.authorize_url + ' to authorize, then enter PIN below')
@jasonrdsouza
jasonrdsouza / GroceryLogic.dart
Last active Jul 7, 2018
Grocery List App Brainstorm
View GroceryLogic.dart
/*
* The basic idea is to make a Grocery List progressive web app in Dartlang,
* using Firestore (https://firebase.google.com/docs/firestore/) as the backend.
* This pad is a quick sketch of the logic necessary to get the app working.
*/
enum Categories {
produce,
dairy,
household,
@jasonrdsouza
jasonrdsouza / aws-restarter.py
Created Dec 13, 2016
Helper script to quickly restart all of the instances of an app running in AWS under a load balancer
View aws-restarter.py
'''
Helper script to quickly restart all of the instances of a specific app
Assumes lots of things about the setup of the app (load balancer, ssh access, supervisor, etc.)
'''
import boto3
import subprocess
import argparse
def load_balancer_instances(name):
@jasonrdsouza
jasonrdsouza / heap.py
Created Nov 8, 2016
Simple Heap Implementation
View heap.py
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 Sep 8, 2020
Export archived article data from Pocket
View pocket_exporter.py
'''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 Sep 10, 2020
Python script to efficiently concatenate S3 files
View combineS3Files.py
'''
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 Aug 29, 2015
Caesar Cipher Decryption Script
View caesar_cipher_decrypt.py
"""
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)
You can’t perform that action at this time.