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
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 =

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]+(, )?)+$')
% 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
In [1]: from schema_object import SchemaObject
In [2]: class Person(SchemaObject):
...: first_name = None
...: last_name = None
...: email = None
...:
In [3]: Person()
Out[3]: Person()
@rshk
rshk / gist:8242161
Created January 3, 2014 17:24
Jquery Windows
<!DOCTYPE html>
<html><head>
<title>Blah</title>
<style>
body {
background: #ddd;
}
#my-window {
position:absolute;
@rshk
rshk / Example Usage
Last active January 1, 2016 08:19
CliTools with Flask
% pse_admin --help
usage: cli-app [-h] {run,db_init} ...
positional arguments:
{run,db_init} sub-commands
run
db_init
optional arguments:
-h, --help show this help message and exit
@rshk
rshk / .xinitrc
Created November 26, 2013 14:42
#!/bin/bash
## Set a decent keyboard layout..
setxkbmap -layout us -variant altgr-intl &
## This is needed for compositing
(
xrandr --output DP-2 --preferred --primary --pos 0x0 --output LVDS-1 --preferred --pos 1920x300 \
|| xrandr --output DP-2 --preferred --primary --output LVDS-1 --preferred --right-of DP-2 \
|| xrandr --output LVDS-1 --preferred --primary