Skip to content

Instantly share code, notes, and snippets.

😎
Being awesome

Samuele Santi rshk

😎
Being awesome
Block or report user

Report or block rshk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rshk
rshk / fields.py
Last active May 24, 2018
Flask-GraphQL Apollo file upload quickfix
View fields.py
import graphene
class FileUpload(graphene.Scalar):
@staticmethod
def serialize(value):
return None
@staticmethod
@rshk
rshk / lipsum.js
Created Sep 4, 2017
Simple Lorem Ipsum generation in Javascript.
View lipsum.js
// 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 Jul 27, 2017
Get solar data from hamqsl.com XML
View solardata.py
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'
View elosort.py
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':
View Dice_rolls_to_bytes.md

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 Aug 29, 2016
build-docker-image.sh
View 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}"
View README.md

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

View leftpad.js
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 Jul 12, 2016
Fix ionic2 build output
View fix-ionic-output.py
# 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]+(, )?)+$')
View output.txt
% py.test -vvv test_py2_logging.py
================================================================================================================================================== test session starts ===================================================================================================================================================
platform linux2 -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1 -- /tmp/tmp.x9LSkBqfG8/.venv2.7/bin/python2.7
cachedir: .cache
rootdir: /tmp/tmp.x9LSkBqfG8, inifile:
collected 4 items
test_py2_logging.py::test_logging_bytes_to_bytes PASSED
test_py2_logging.py::test_logging_unicode_to_bytes PASSED
test_py2_logging.py::test_logging_bytes_to_unicode PASSED
You can’t perform that action at this time.