Skip to content

Instantly share code, notes, and snippets.

# problem in - https://leetcode.com/problems/decode-string/
import string
class Number(object):
def __init__(self, i):
self.unparsed = i
def append(self, obj):
self.unparsed += self.unparsed
def value(self):
@t3rmin4t0r
t3rmin4t0r / recursive-descent.py
Created October 14, 2022 06:26
Recursive descent parser example
class Literal(object):
def __init__(self, c):
self.literal = c
def append(self, c):
self.literal += c
def __repr__(self):
return ("<Literal '%s'>" % self.literal)
class Nested(object):
@t3rmin4t0r
t3rmin4t0r / El Capitan Disk maker for M1 Mac
Last active May 1, 2022 02:09
How to make an El Capitan usb bootable disk from an M1 Mac
# verbatim copied over from - https://apple.stackexchange.com/a/420325
# Download install DMG for El Capitan
# https://support.apple.com/en-us/HT211683
wget -c http://updates-http.cdn-apple.com/2019/cert/061-41424-20191024-218af9ec-cf50-4516-9011-228c78eda3d2/InstallMacOSX.dmg
# mount and unzip the packager
pkgutil --expand InstallMacOSX.pkg Installer
@t3rmin4t0r
t3rmin4t0r / 9x.md
Last active November 25, 2021 22:08
ABC + DEF + GHI = 123J, solve for J

ABC + DEF + GHI = 123J

All letters represent unique numbers between 0-9

Basic starting point: If you subtract all the digits from a number, you get a multiple of 9

ABC = 100 x A + 10 x B + C = (99 x A + 9 x B) + A + B + C = 9 (11 x A + B) + A + B + C

Inversely stated, it means

; Variable declarations
(declare-fun a () Int)
(declare-fun b () Int)
(declare-fun c () Int)
(declare-fun d () Int)
(declare-fun e () Int)
(declare-fun f () Int)
(declare-fun g () Int)
(declare-fun h () Int)
(declare-fun i () Int)
@t3rmin4t0r
t3rmin4t0r / PriorityQueueTest.java
Last active October 19, 2020 07:16
You would expect a PriorityHeap to push down an item, but what if it actually does it upwards & is a PriorityQueue instead
package org.notmysock.test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.PriorityQueue;
import org.junit.jupiter.api.Test;
class PriorityQueueTest {
@t3rmin4t0r
t3rmin4t0r / tpcds_first_names.awk
Last active March 17, 2020 20:30
TPC-DS dist to first_names.awk
grep "^add.*,.*," names.dst | \
sed -e "s/:/,/" -e "s/^add/,/" -e "s/;//" \
| awk 'BEGIN {print "create temporary table first_names(name String, male int, female int, neutral int);"} \
/^,/ {if(NR % 1000 == 1) {print "; insert into first_names values", substr($0,2)} else {print} } '\
> names.sql
@t3rmin4t0r
t3rmin4t0r / yarn_app_logs_splitter.py
Created October 4, 2019 22:19
yarn_app_logs_splitter.py script
#! /usr/bin/env python
# Simple tool to take the logs generated by yarn logs -applicationId
# and convert them into separate log files.
# Current implementation deconstructs the monolith log dump
# into multiple files in the format <container_id>.<log_file_name>
# For example, container_1400495557557_0001_01_000001.syslog
import argparse
import os
@t3rmin4t0r
t3rmin4t0r / parse.py
Created January 28, 2019 06:15
TPC-DS schema parser
import sys
import re
PK_POS=re.compile(r'\(([0-9])\)')
class SourceCol(object):
def __init__(self, data):
"""
['ss_sold_date_sk', 'identifier', '', '', 'd_date_sk', 'Y']
['c_customer_id (B)', 'char(16)', 'N', 'U']
"""
@t3rmin4t0r
t3rmin4t0r / unpaginate.py
Last active March 13, 2019 21:16
Remove beeline pagination from a query result
import sys
sample="""
+------------------------------------------------------------------+--+
| createtab_stmt |
+------------------------------------------------------------------+--+
| CREATE TABLE `finance.xx_po_headers`( |
| `po_header_id` bigint, |
| `requester_name` string, |
+------------------------------------------------------------------+--+