Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
lyoshenka / email-ping.py
Last active August 29, 2015 14:04
Sends an email to your account that you want Gmail to check more frequently. Run this in cron for a week or two.
#!/usr/bin/env python
# for crontab
# */5 9-22 * * * /home/grin/bin/cronic /usr/bin/python /home/grin/email-ping.py
# */15 23,0-8 * * * /home/grin/bin/cronic /usr/bin/python /home/grin/email-ping.py
import smtplib, time, sys
from email.mime.text import MIMEText
from_email = ''
@lyoshenka
lyoshenka / rain_alert.sh
Last active August 3, 2019 07:24
Probability that it will rain near you in the next half-hour
# requires python, jq
# get your API key from https://developer.forecast.io/
API_KEY=
# enter the latitude and longitude for your location
LAT=
LNG=
CHANCE=$( curl -s https://api.forecast.io/forecast/API_KEY/LAT,LNG?exclude=hourly,daily,alerts,flags | jq .minutely.data[].precipProbability | head -n 30 | python -c 'import sys; print(max(float(x) for x in sys.stdin.readlines()))' )
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | python
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | USERNAME=lyoshenka python
# USERNAME=lyoshenka python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
@lyoshenka
lyoshenka / ssl_oneline.sh
Created June 23, 2014 13:31
One-liner to create a self-signed SSL cert
#!/bin/bash
# http://stackoverflow.com/questions/10175812/how-to-build-a-self-signed-certificate-with-openssl
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 10000
# if you don't want a password for your cert
openssl genrsa -out key.pem 4096 && openssl req -x509 -new -nodes -key key.pem -out cert.pem -days 10000 -subj "/CN=DOMAIN"
@lyoshenka
lyoshenka / ngrok-selfhosting-setup.md
Last active February 21, 2025 08:33
How to setup Ngrok with a self-signed SSL cert

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

eyJ2ZXJzaW9uIjoxLjMsImZlYXR1cmVzIjp7ImxvY2F0aW9uIjp7InJvb20iOnRydWUsIm91dHNpZGUiOnRydWUsIndvcmxkIjp0cnVlfX0sInN0b3JlcyI6eyJ3b29kIjo4NDY3LCJtZWF0IjozOTEuNSwiYmFpdCI6MjMyLCJzY2FsZXMiOjE0NywidGVldGgiOjI4NiwiZnVyIjo0ODI3LjUsImNsb3RoIjoxOTYsImNoYXJtIjo0LCJjdXJlZCBtZWF0IjoyNjQsImNvbXBhc3MiOjEsImxlYXRoZXIiOjExOCwibWVkaWNpbmUiOjgsImJvbmUgc3BlYXIiOjEsInRvcmNoIjoxNiwibCBhcm1vdXIiOjEsIndhdGVyc2tpbiI6MSwicnVja3NhY2siOjEsImlyb24iOjYwMSwiaXJvbiBzd29yZCI6MCwiY2FzayI6MSwid2Fnb24iOjEsInN0ZWVsIHN3b3JkIjoxLCJzdGVlbCI6MjY4LCJpIGFybW91ciI6MSwiY29hbCI6OTIsImJ1bGxldHMiOjAsImJvbGFzIjowLCJzIGFybW91ciI6MSwiY29udm95IjoxLCJ3YXRlciB0YW5rIjoxLCJyaWZsZSI6MH0sImNoYXJhY3RlciI6eyJwdW5jaGVzIjo0MCwic3RhcnZlZCI6MSwicGVya3MiOnsic3RlYWx0aHkiOnRydWV9fSwiaW5jb21lIjp7ImdhdGhlcmVyIjp7ImRlbGF5IjoxMCwic3RvcmVzIjp7Indvb2QiOjIwfSwidGltZUxlZnQiOjl9LCJidWlsZGVyIjp7ImRlbGF5IjoxMCwic3RvcmVzIjp7Indvb2QiOjJ9LCJ0aW1lTGVmdCI6MX0sImh1bnRlciI6eyJkZWxheSI6MTAsInN0b3JlcyI6eyJmdXIiOjIzLjUsIm1lYXQiOjIzLjV9LCJ0aW1lTGVmdCI6MTB9LCJ0cmFwcGVyIjp7ImRlbGF5IjoxMCwic3RvcmVzIjp7
@lyoshenka
lyoshenka / aws_bucket.sh
Created May 13, 2014 16:07
Create an AWS bucket and a user with access only to that bucket. Requires awscli set up.
#!/usr/bin/env bash
#
# Based on BASH3 Boilerplate v0.1.0 (https://github.com/kvz/bash3boilerplate)
#
# Usage:
# LOG_LEVEL=7 ./aws_bucket.sh -b BUCKETNAME
#
### Configuration
@lyoshenka
lyoshenka / santa.php
Last active August 29, 2015 14:00
Script to send out secret santa assignments
#!/usr/bin/php
<?php
// santa file has the following format
//
// name1 [email protected]
// another name [email protected]
// etc...
$myEmail= 'YOUR EMAIL HERE';
@lyoshenka
lyoshenka / redshift.conf
Last active August 29, 2015 14:00
Upstart script for Redshift (http://jonls.dk/redshift/)
# Redshift upstart script
#
# IMPORTANT: you have to specify your lat/lng manually, or redshift won't start. Either put
# it in your config file or pass it explicitly
#
description "Redshift"
start on runlevel [2345]
stop on runlevel [!2345]

Deploy your own PaaS!

Setting up Dokku with DigitalOcean and Namecheap

..or how I made my own heroku in a few hours for $3.98.

This write-up owes a great deal to dscape's Node.js Deployments with Docker, Dokku, & Digital Ocean, the dokku project itself, and the fine folks working on dokku's issues. I took dscape's article as a starting point when trying this out but found some details lacking so I documented my own process for getting dokku up and running.

1. Get a domain