Skip to content

Instantly share code, notes, and snippets.

@maurisvh
maurisvh / spectrogram.py
Last active January 27, 2025 18:47
ANSI art spectrogram viewer that reads audio from a microphone
#!/usr/bin/python
import numpy
import pyaudio
import re
import sys
WIDTH = 79
BOOST = 1.0
@yuecen
yuecen / kibana-ldap.conf
Created September 22, 2015 02:39
Kibana with Auth using mod_auth_ldap
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Location /elastichq>
#Order allow,deny
#Allow from all
AuthUserFile /etc/apache2/.htpasswd
AuthType Basic
AuthName "Username and Password"
Require valid-user
@msabramo
msabramo / mock_patch_multiple_targets.py
Created September 11, 2015 19:42
Mock patch multiple targets in Python
@contextlib.contextmanager
def multiple_targets(mock_patches):
"""
`mock_patches` is a list (or iterable) of mock.patch objects
Example usage:
with mock.patch.multiple_targets([
mock.patch('os.path.exists', side_effect=mock_path_exists),
mock.patch('subprocess.Popen'),
@Battleroid
Battleroid / flatten.py
Created August 2, 2015 20:32
Flatten defaultdict to list using chain.
from collections import defaultdict, namedtuple
from itertools import chain
ex = namedtuple('ex', ['name', 'desc'])
items = defaultdict(lambda: defaultdict(ex))
# items is populated with a bunch of stuff like:
# [1] -> integer key, such as group 1, group 2, so on
# |-> ex('apple', 'a fruit')
# [2]
@mdwhatcott
mdwhatcott / custom_json.go
Created July 29, 2015 17:15
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@amitu
amitu / 01-datastructures.md
Last active August 29, 2015 14:24
book stuff

There is plenty we can do with strings, we have already seen .upper() in previous chapter.

>>> message = u"hello world"
>>> message.upper()
u'HELLO WORLD'
@cstrelioff
cstrelioff / README.md
Last active June 4, 2018 16:31
decision trees: scikit-learn + pandas

decision trees: scikit-learn + pandas

This script provides an example of learning a decision tree with scikit-learn. Pandas is used to read data and custom functions are employed to investigate the decision tree after it is learned. Grab the code and try it out.

A blog post about this code is available here, check it out!

@FND
FND / README.md
Last active August 30, 2024 04:42
Falcon WSGI application with asyncio

Getting Started

$ pip install falcon
$ python3 app.py

alternatively with Gunicorn (for HTTP/1.1):

$ pip install gunicorn

$ gunicorn app:app

@Battleroid
Battleroid / smb.conf
Last active August 12, 2017 23:40
Basic samba config that require user login. So I never forget.
[global]
# after default setup
socket options = IPTOS_LOWDELAY TCP_NODELAY
security = user
[sample_writeable]
path = /srv/path
public = yes
browseable = yes
valid users = youruser, anotheruser, etc
@waveform80
waveform80 / motion_215.py
Last active September 8, 2021 16:23
Motion detection with a circular buffer and file recording in picamera
#!/usr/bin/env python
import io
import time
import picamera
import picamera.array
import numpy as np
from PIL import Image, ImageDraw