Skip to content

Instantly share code, notes, and snippets.

View otienog1's full-sized avatar

George Otieno otienog1

View GitHub Profile
function getVideoImage(path, secs, callback) {
var me = this, video = document.createElement('video');
video.onloadedmetadata = function() {
if ('function' === typeof secs) {
secs = secs(this.duration);
}
this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
};
video.onseeked = function(e) {
var canvas = document.createElement('canvas');
function fitInto(desiredWidth, desiredHeight, actualWidth, actualHeight) {
var actualSlope = actualHeight / actualWidth;
if (isFinite(actualSlope || '@')) {
if (desiredHeight / desiredWidth > actualSlope) {
desiredHeight = desiredWidth * actualSlope;
}
else {
desiredWidth = desiredHeight / actualSlope;
}
}
function watermarkImage(elemImage, text) {
// Create test image to get proper dimensions of the image.
var testImage = new Image();
testImage.onload = function() {
var h = testImage.height, w = testImage.width, img = new Image();
// Once the image with the SVG of the watermark is loaded...
img.onload = function() {
// Make canvas with image and watermark
var canvas = Object.assign(document.createElement('canvas'), {width: w, height: h});
var ctx = canvas.getContext('2d');
# coding=utf-8
"""
LICENSE http://www.apache.org/licenses/LICENSE-2.0
"""
import datetime
import sys
import time
import threading
import traceback
import SocketServer
@otienog1
otienog1 / dns_server.py
Created August 27, 2018 06:41 — forked from samuelcolvin/dns_server.py
requires python 3.5+ and dnslib, see https://github.com/samuelcolvin/dnserver for full/better implementation
from datetime import datetime
from time import sleep
from dnslib import DNSLabel, QTYPE, RD, RR
from dnslib import A, AAAA, CNAME, MX, NS, SOA, TXT
from dnslib.server import DNSServer
EPOCH = datetime(1970, 1, 1)
SERIAL = int((datetime.utcnow() - EPOCH).total_seconds())
import cgi
import http
import mimetypes
import os
import shutil
import urllib.parse
STORAGE_PATH = os.environ.get('STORAGE_PATH') or \
os.path.dirname(__file__) + '/storage'
from collections import OrderedDict
import json
from urllib.request import urlopen
import xml.etree.ElementTree as ET
xml = urlopen(url=url).read()
items = []
for item in ET.fromstring(xml).findall('channel')[0].findall('item'):
items.append(OrderedDict((i.tag, i.text) for i in item))
from datetime import datetime, timezone, timedelta
def convert_timezone(dtm, z='utc'):
t_utc = (dtm - (dtm.utcoffset() or timedelta()))
t_utc = t_utc.replace(tzinfo=timezone.utc)
z = z.lower().replace('utc', '').replace(' ', '').replace(':', '')
if not z:
return t_utc
if len(z) == 3:
# coding=utf-8
import base64
from urllib2 import urlopen
import tempfile
import os
import tk
import json
class App(tk.Tk):
@otienog1
otienog1 / stream.sh
Created August 27, 2018 06:49 — forked from andreif/stream.sh
#!/bin/sh -xe
API_KEY="YOUR_API_KEY_GOES_HERE"
FPS="10"
VLC_PATH="/Applications/VLC.app/Contents/MacOS/VLC"
# I don't know how this'll behave on multimon, so you might want to hard-code.
# INRES='1440x900'
INRES=$(osascript -e 'tell application "Finder" to get bounds of window of desktop'|sed 's/, /x/g'|cut -f3- -dx)
OUTRES='1280x800'
# You can change this to record microphone or something else, from man soxformat (under coreaudio):