Skip to content

Instantly share code, notes, and snippets.

@iaverin
iaverin / rest35.py
Last active September 5, 2023 19:58
Simple and functional REST server for Python (3.5) using no dependencies beyond the Python standard library. Ported from https://gist.github.com/tliron/8e9757180506f25e46d9
#!/usr/bin/env python
'''
Simple and functional REST server for Python (3.5) using no dependencies beyond the Python standard library.
Ported from original lib for Python 2.7 by Liron (tliron @ github.com) https://gist.github.com/tliron/8e9757180506f25e46d9
Features:
* Map URI patterns using regular expressions
* Map any/all the HTTP VERBS (GET, PUT, DELETE, POST)
* All responses and payloads are converted to/from JSON for you
* Easily serve static files: a URI can be mapped to a file, in which case just GET is supported
@fedden
fedden / frequency_modulation_visualisation.py
Last active December 1, 2020 10:54
Frequency modulation Python matplotlib visualisation
import numpy as np
import matplotlib.pyplot as plt
modulator_frequency = 4.0
carrier_frequency = 40.0
modulation_index = 1.0
time = np.arange(44100.0) / 44100.0
modulator = np.sin(2.0 * np.pi * modulator_frequency * time) * modulation_index
carrier = np.sin(2.0 * np.pi * carrier_frequency * time)
@KazWolfe
KazWolfe / Recurse.java
Last active January 24, 2017 00:40
Recursively list directories/files through Java
/*
* Recursively list directories/files through Java, akin to Linux's `ls -R` command.
* (c) 2017, KazWolfe. Under MIT license.
*
* To use, save to `Recurse.java` and compile with `javac Recurse.java`.
* Run with `java -cp . Recurse /path/to/operate/on`. Be sure you are passing in a folder.
*/
import java.io.File;
import java.lang.String;
@KazWolfe
KazWolfe / ProgrammerMilk.java
Last active July 15, 2016 02:07
Programmer Milk
// Inspired by the joke:
// "A programmer was walking out the door for work when
// his wife said, 'While you're out, buy some milk.'
// The programmer never came home.
programmer.getToDoList().getLocationList().addItem(Location.ANYWHERE, () -> {programmer.moveTo(Location.SUPERMARKET);});
programmer.getToDoList().getLocationList().addItem(Location.SUPERMARKET, (neededAmount) -> {
// Get the price and inventory from the Economy.
double price = Economy.getStore(Store.SUPERMARKET).getInventory().getItemClass(ItemClass.MILK).getPrice();
@alces
alces / ansible_local_playbooks.md
Last active April 5, 2024 18:28
How to run an Ansible playbook locally
  • using Ansible command line:
ansible-playbook --connection=local 127.0.0.1 playbook.yml
  • using inventory:
127.0.0.1 ansible_connection=local
@claymcleod
claymcleod / pycurses.py
Last active May 1, 2024 14:44
Python curses example
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
@allquixotic
allquixotic / Ubuntu.md
Created December 21, 2015 16:10
My Ubuntu Experience

Intro

I have been using some flavor of GNU/Linux (which excludes Android) since about 2002. The first distro I ever installed was Lindows, and while I often used Lindows as my "main" distro because it was so easy to use, I was very much a distro shopper in my early years. I'd find a spare USB hard drive or flash drive and throw Gentoo or Debian or openSUSE or Fedora on it. It wasn't until the release of Ubuntu 8.04, Hardy Heron, that I finally settled on a "preferred" distro: Ubuntu. And, unlike its commercial open source relative, Linspire, Ubuntu didn't run out of money and stop development. So that was a big plus.

Also unlike its other more distant relative, Fedora, Ubuntu had a more predictable release schedule, and longer support for each release. This meant I could feel free to use a crusty old installation on a dedicated server and be confident that I'd continue to receive critical security updates for years to come. And that's exactly what I did: starting around 2006, I have had either a dedicated

@tliron
tliron / rest.py
Last active January 8, 2022 13:34
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library.
#!/usr/bin/env python
'''
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library.
Features:
* Map URI patterns using regular expressions
* Map any/all the HTTP VERBS (GET, PUT, DELETE, POST)
* All responses and payloads are converted to/from JSON for you
@nathan-osman
nathan-osman / ip-indicator.py
Last active April 2, 2018 23:37
IP Address AppIndicator
#!/usr/bin/env python2
import appindicator
import gtk
import urllib2
class IPIndicator(appindicator.Indicator):
"""
An indicator displaying public IP address.
@dyerw
dyerw / coroutines.py
Created January 6, 2015 17:09
A simple producer/consumer example using python coroutines
import random
def coroutine(func):
"""A decorator to automatically prime coroutines"""
def start(*args, **kwargs):
cr = func(*args, **kwargs)
next(cr)
return cr
return start