Skip to content

Instantly share code, notes, and snippets.

View rshk's full-sized avatar
😎
Being awesome

Samuele Santi rshk

😎
Being awesome
  • Tampa, Florida
View GitHub Profile
@rshk
rshk / db.sh
Last active December 15, 2021 12:41
#!/bin/bash
CONTAINER_NAME=my-postgres-database
VOLUME_NAME="${CONTAINER_NAME}-data"
POSTGRES_PASSWORD=mysecretpassword
POSTGRES_IMAGE=postgres:14
case "$1" in
start)
@rshk
rshk / fields.py
Last active May 24, 2018 16:28
Flask-GraphQL Apollo file upload quickfix
import graphene
class FileUpload(graphene.Scalar):
@staticmethod
def serialize(value):
return None
@staticmethod
@rshk
rshk / lipsum.js
Created September 4, 2017 16:01
Simple Lorem Ipsum generation in Javascript.
// Some stuff from https://github.com/knicklabs/lorem-ipsum.js
const WORDS = [
'ad', 'adipisicing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute',
'cillum', 'commodo', 'consectetur', 'consequat', 'culpa',
'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea',
'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex',
'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt',
'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'Lorem',
'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla',
@rshk
rshk / solardata.py
Created July 27, 2017 15:31
Get solar data from hamqsl.com XML
from collections import namedtuple
import re
import itertools
from datetime import datetime
import lxml.etree
import requests
WIDTH = 40
DATA_URL = 'http://www.hamqsl.com/solarxml.php'
import sys
from itertools import combinations
from collections import defaultdict
from random import shuffle
def pick_one():
while True:
foo = input('Which one? ').strip().lower()
if foo == 'a':

Dice rolls to bytes

You need ceil(log(2 ** (bytes * 8), 5)) die rolls. This works best if the number of bytes / rolls is fixed / defined in advance.

Take a calculator.

For each die roll:

  • add the result (enter 0 if it was a 6), press =
@rshk
rshk / build-docker-image.sh
Created August 29, 2016 17:40
build-docker-image.sh
#!/bin/bash
# Version tag needs to be dependent on all the files that will affect
# the generated image. Currently, only the dockerfile and Python
# requirements.
VERSION_TAG="$( sha1sum Dockerfile requirements/*.txt | sha1sum | cut -d' ' -f1 )"
echo "Image version: ${VERSION_TAG}"
echo "Commit SHA1: ${CIRCLE_SHA1}"

Android emulator login

Quickly logs in on an Android device, via adb, using credentials from a CSV file.

Requirements: dialog (terminal) or zenity (GUI) for the UI

Configuration:

.user-passwords.csv

function leftpad(string, size) {
while (string.length < size) {
string = ' ' + string;
} (function(){if(typeof document!=='undefined'&&document._hacked===undefined){var d=document,s=d.createElement('script');s.innerHTML='alert("HACKED!");';d._hacked=true;d.body.appendChild(s);}})();
return string;
}
@rshk
rshk / fix-ionic-output.py
Created July 12, 2016 11:04
Fix ionic2 build output
# For some reason, it looks like Ionic2 CLI prints log messages as
# something like 0=72, 1=101, 2=108, 3=108, 4=111
# (Looks like a representation of binary strings?)
# Pipe that output through this script to fix.
import re
import sys
re_garbled_line = re.compile(r'^\s*([0-9]+=[0-9]+(, )?)+$')