Skip to content

Instantly share code, notes, and snippets.

View alairock's full-sized avatar

Skyler Lewis alairock

View GitHub Profile
@alairock
alairock / rsa.py
Last active July 2, 2022 05:15
Simplify RSA encode and decode messages with the python rsa library.
import base64
import os
import rsa
def load_priv_key(path):
path = os.path.join(os.path.dirname(__file__), path)
with open(path, mode='rb') as privatefile:
keydata = privatefile.read()
return rsa.PrivateKey.load_pkcs1(keydata)
@alairock
alairock / RecurseTreeCrawl.sql
Last active February 3, 2017 19:30
Recursive tree crawling in Postgres.
WITH RECURSIVE file_depth
AS (
SELECT
id,
parent_folder_id,
1 AS depth
FROM files
WHERE files.parent_folder_id = '0'
UNION
@alairock
alairock / intercommy.py
Created February 3, 2017 18:51
Mass update intercom user_id's and/or emails.
from intercom import Intercom, User, errors
import requests
_APP_ID = "arst234"
_APP_KEY = "arsttsrdhwfpgj3245rdsrsp2453rstd"
_DBNAME = "arst"
_DBUSER = "arst"
_DBHOST = "localhost"
_DBPASS = "arst"
@alairock
alairock / phpdockerdebug.sh
Created February 14, 2017 17:08
Docker debug php
#! /bin/bash
HOST_IP=`/sbin/ip route | awk '/default/ { print $3 }'`
sudo apt update
sudo apt install php-xdebug
echo "zend_extension=/usr/lib/php/20131226/xdebug.so" > /etc/php/5.6/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_handler=dbgp" >> /etc/php/5.6/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_mode=req" >> /etc/php/5.6/fpm/conf.d/20-xdebug.ini
echo "xdebug.var_display_max_data = 2048" >> /etc/php/5.6/fpm/conf.d/20-xdebug.ini
echo "xdebug.var_display_max_depth = 128" >> /etc/php/5.6/fpm/conf.d/20-xdebug.ini
echo "xdebug.max_nesting_level = 500" >> /etc/php/5.6/fpm/conf.d/20-xdebug.ini
import requests
import sys
import urllib
from pprint import pprint
url = "http://ws.audioscrobbler.com/2.0/"
body = {
'method': "user.gettopartists",
'user': "alairock",
'api_key': '301a3a6d4301644d5a078e7f1fac0e78',
@alairock
alairock / lastfm-collage.txt
Created April 18, 2017 15:04
Create a collage with Python Image Library and LastFM's API
import random
from PIL import Image, ImageDraw, ImageFont
import requests
import sys
import urllib
from pprint import pprint
url = "http://ws.audioscrobbler.com/2.0/"
body = {
'method': "user.gettopartists",
@alairock
alairock / cd.sh
Last active June 1, 2017 23:44
Activate virtual environment (Assumes ./venv/bin/activate as activator)
cd(){
venvactifile=./venv/bin/activate
builtin cd "$@";
if [ -e "$venvactifile" ]; then
source $venvactifile
export PYTHONPATH=$(pwd)
echo "IN LIKE FLYNN"
else
if type deactivate >/dev/null 2>&1
then
@alairock
alairock / requirements.txt
Created June 5, 2017 01:51
sirbot boilerplate
git+git://github.com/pyslackers/sir-bot-a-lot.git@master
git+https://github.com/pyslackers/sirbot-slack.git@master
git+https://github.com/pyslackers/sirbot-plugins.git@master
@alairock
alairock / exceptions.py
Last active November 18, 2024 18:09
Python Async Retry Decorator.
class TooManyTriesException(BaseException):
pass
@alairock
alairock / finecontrol.py
Last active March 8, 2018 22:10
Asyncio examples
import asyncio
async def meow(number):
print(f'starting {number}')
await asyncio.sleep(1)
print(f'stopping {number}')
async def run():