Skip to content

Instantly share code, notes, and snippets.

Me: "at least you're not using throwaway variables"
>>> _ = 'hardware'
>>> __ = 'hwardhware'
>>> ___ = {_: {__: 'hwhwhwhwhwhw'}}
>>> ____ = [_____ for _____ in ___ for ______ in ___[_____]]
>>> ____
['hardware']
Coworker: "oh god oh fuck oh no"
@Resisty
Resisty / chunks.py
Created September 17, 2020 13:35
Divide list 'lst' into num-sized chunks
def chunks(lst, num):
""" Divide list 'lst' into num-sized chunks
"""
for i in range(0, len(lst), num):
yield lst[i: i+num]
@Resisty
Resisty / fizzbuzz.py
Created July 13, 2020 03:12
Exception-Driven FizzBuzz
def fb(i, n):
try:
assert i <= n
three = i % 3
five = i % 5
p0d = 1/(three+five)
pve = int('0'*five)
pke = {1:'',2:''}[three]
print i
except ZeroDivisionError:
@Resisty
Resisty / reverse.sh
Created February 28, 2020 22:13
Awful Bash String Reverse
#!/usr/bin/env bash
# This was done as a joke at work when we were talking about interview questions.
# I am unashamed.
string="$1"
for (( i=0; i<${#string}; i++ ));
do
{ eval "sleep \$(expr \${#string} - \$i) && printf '%s' '${string:$i:1}'" & } 2>/dev/null
done
echo
@Resisty
Resisty / .vimrc
Created August 23, 2018 17:08
Increasingly large (and maybe shitty) .vimrc
" vimrc file for following the coding standards specified in PEP 7 & 8.
"
" To use this file, source it in your own personal .vimrc file (``source
" <filename>``) or, if you don't have a .vimrc file, you can just symlink to it
" (``ln -s <this file> ~/.vimrc``). All options are protected by autocmds
" (read below for an explanation of the command) so blind sourcing of this file
" is safe and will not affect your settings for non-Python or non-C files.
"
"
" All setting are protected by 'au' ('autocmd') statements. Only files ending
@Resisty
Resisty / kms_helper.py
Last active July 18, 2018 17:19
KMS Helper
#!/usr/bin/env python
''' Helper script for working with AWS KMS
'''
import sys
import base64
import argparse
import boto3
def decrypt_args(args):
''' Check args for decrypt function and call it appropriately
'''
@Resisty
Resisty / __init__.py
Last active July 13, 2018 21:42
setup.py
#!/usr/bin/env python
''' This module serves as a weird example for some nonsense for a friend
Place this file in chbuildstatus/
'''
import argparse
import logging
import re
import requests
FORMAT = """[%(asctime)s] '%(message)s'"""
@Resisty
Resisty / README.md
Created September 12, 2017 15:33 — forked from iMilnb/README.md
AWS Terraform configuration: Stream CloudWatch Logs to ElasticSearch

Rationale

This snippet is a sample showing how to implement CloudWatch Logs streaming to ElasticSearch using terraform. I wrote this gist because I didn't found a clear, end-to-end example on how to achieve this task. In particular, I understood the resource "aws_lambda_permission" "cloudwatch_allow" part by reading a couple of bug reports plus this stackoverflow post.

The js file is actually the Lambda function automatically created by AWS when creating this pipeline through the web console. I only added a endpoint variable handling so it is configurable from terraform.

#!/bin/python3
import sys
import collections
n,m = input().strip().split(' ')
n,m = [int(n),int(m)]
topic = []
topic_i = 0
for topic_i in range(n):
#!/bin/python3
ROW = 0
COL = 1
def num_queen_attacks(boardlen, queen, obs):
counts = [0] * 8 # queen can attack in eight directions, moving clockwise:
# 0 is North, 1 is NE, etc
counts[0] = queen[ROW]
counts[1] = min([queen[ROW], boardlen - queen[COL] - 1])