Skip to content

Instantly share code, notes, and snippets.

View djosix's full-sized avatar
🐑
In a relationsheep

Yuan-Kui Li djosix

🐑
In a relationsheep
View GitHub Profile
#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method
@endolith
endolith / readme.md
Last active May 22, 2024 07:13
How to stream a webcam to a web browser in Ubuntu

Grr this took hours to figure out. I was trying to install MJPG-streamer and running VLC command lines and all this crap but nothing worked.

First install motion:

~> sudo apt-get install motion

Then create a config file:

~> mkdir ~/.motion

~> nano ~/.motion/motion.conf

@rochacbruno
rochacbruno / haversine.py
Created June 6, 2012 17:43
Calculate distance between latitude longitude pairs with Python
#!/usr/bin/env python
# Haversine formula example in Python
# Author: Wayne Dyck
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
@taldanzig
taldanzig / osxvpnrouting.markdown
Created January 24, 2013 22:14
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@JalfResi
JalfResi / revprox.go
Last active May 18, 2024 00:23
Simple reverse proxy in Go
package main
import(
"log"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {
@Sesim
Sesim / Scraper for Twitter Hashtag
Last active October 10, 2019 12:46
Scraper for Twitter Hashtag
# Finding topics of interest by using the filtering capablities it offers.
import twitter
import json
import sys
import csv
csvfile = open('YOUR DATA BASE NAME.csv','a')
csvwriter = csv.writer(csvfile)
# == OAuth Authentication ==
@gnilchee
gnilchee / http_multithreaded.py
Last active March 12, 2024 13:54
Multi-threaded Python3 HTTP Server
#!/usr/bin/env python3
import sys, os, socket
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@arnaldorusso
arnaldorusso / midi2mp3
Created January 24, 2016 13:45 — forked from kroger/midi2mp3
Convert MIDI files to MP3 using fluidsynth. See
#!/usr/bin/env bash
SOUNDFONT=/Users/kroger/Dropbox/Sfonts/BOPLMEVF16.sf2
TMPDIR=/tmp
if [[ ! -f $SOUNDFONT ]]
then
echo "Couldn't find the soundfont: $SOUNDFONT"
exit 1
@robbiev
robbiev / priority_select.go
Last active January 21, 2023 18:27
select with priority in go
// SOLUTION 1
// see https://groups.google.com/forum/#!topic/golang-nuts/ChPxr_h8kUM
func maybe(b bool, c chan int) chan int {
if !b {
return nil
}
return c
}
select {
import asyncio
loop = asyncio.get_event_loop()
async def hello():
await asyncio.sleep(3)
print('Hello!')
if __name__ == '__main__':
loop.run_until_complete(hello())