Skip to content

Instantly share code, notes, and snippets.

View jstncno's full-sized avatar

Justin Cano jstncno

View GitHub Profile
@jstncno
jstncno / singleton.py
Last active December 17, 2018 21:23
Python Singleton Instance
def singletonmethod(func):
def wrapped_classmethod(cls, *args, **kwargs):
if cls._instance is None or type(cls._instance) != cls:
cls._instance = cls()
return func(cls._instance, *args, **kwargs)
return wrapped_classmethod
class Singleton(object):
"""
@jstncno
jstncno / mov2webm.sh
Created August 14, 2018 16:58
Convert a .mov, decoded as AppleProres w/ an alpha channel, to a Chrome-friendly .webm
# Usage: $ mov2webm.sh input.mov output.webm
INPUT=$1
OUTPUT=$2
# Convert a video file (e.g., .mov decoded as AppleProres w/ alpha channel) to a .webm
# ffmpeg -i $INPUT -c:v libvpx-vp9 -pix_fmt yuva420p output.webm
# Convert a video file (e.g., .mov decoded as AppleProres w/ alpha channel) to .png frames
ffmpeg -i $INPUT frame-%02d.png
@jstncno
jstncno / need_sudo.sh
Last active August 1, 2018 18:27
Bash script that must run with sudo
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)" 1>&2
exit 1
fi
@jstncno
jstncno / _README.md
Created June 21, 2017 06:51 — forked from oleq/_README.md
A2DP audio streaming using Raspberry PI (Raspbian Jessie)

What is this all about?

This tutorial will turn your Raspberry PI into a simple Bluetooth audio receiver, which plays music through connected speakers. It's like a regular car audio system, but it can be used anywhere and it's a good value.

   Audio source (i.e. smartphone) 
                |
                v
 (((  Wireless Bluetooth Channel  )))
 |
# /etc/config/openvpn
# OpenWRT
# https://www.privateinternetaccess.com/forum/discussion/3519/openwrt-router-config-for-always-up-vpn-with-pia
package openvpn
config openvpn pia
# Set to 1 to enable this instance:
@jstncno
jstncno / img2dataUri.js
Created November 22, 2016 03:25
Get data of a remote image. Needs timestamp to get past crossOrigin
// https://davidwalsh.name/convert-image-data-uri-javascript
var getDataUri = function(url, callback) {
var colorThief = new ColorThief();
var image = new Image();
image.onload = function () {
var canvas = document.createElement('canvas');
canvas.id = 'backgroundImg';
canvas.style.display = 'none';
@jstncno
jstncno / .prompt
Last active September 26, 2017 20:45
Shell prompt
function prompt {
local BLACK="\[\033[0;30m\]"
local BLACKBOLD="\[\033[1;30m\]"
local RED="\[\033[0;31m\]"
local REDBOLD="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local GREENBOLD="\[\033[1;32m\]"
local YELLOW="\[\033[0;33m\]"
local YELLOWBOLD="\[\033[1;33m\]"
local BLUE="\[\033[0;34m\]"
@jstncno
jstncno / build.sbt
Created October 30, 2015 19:44 — forked from miguno/build.sbt
build.sbt for Apache Kafka 0.8.0 for Scala 2.10 with sbt 0.13.0. Note: The code uses the Apache Staging repository because we use the latest release candidate (RC) of Kafka 0.8.0. For official Kafka releases you don't need that staging repository.
name := "kafka-0.8-with-scala-2.10-example"
version := "1.0"
scalaVersion := "2.10.3"
sbtVersion := "0.13.0"
// Required to retrieve Kafka 0.8.0-rc5 artifacts; once Kafka 0.8.0 is officially released
// you don't need to use the Apache Staging repo anymore.
@jstncno
jstncno / random_date.py
Created August 24, 2015 22:33
Random Python timestamp
# http://stackoverflow.com/questions/553303/generate-a-random-date-between-two-other-dates#answer-553320
import random, time
def str_time_prop(start, end, format, prop):
'''Get a time at a proportion of a range of two formatted times.
start and end should be strings specifying times formated in the
given format (strftime-style), giving an interval [start, end].
prop specifies how a proportion of the interval to be taken after
start. The returned time will be in the specified format.
@jstncno
jstncno / gist:ed7d6a307278152df93d
Created June 10, 2015 18:48
Change Bash Prompt
# Append to ~/.profile...
PS1="master:~ $"
changePrompt() {
if [ "$PWD" == "$HOME" ]; then
PS1="master:~ $ "
else
PS1="master:${PWD##*/} $ "
fi
}