Skip to content

Instantly share code, notes, and snippets.

@garnaat
garnaat / bucket_du.py
Created September 1, 2011 13:15
Get total bytes in a bucket
# Iterates over all the keys in a bucket and totals the bytes used
# NOTE: if you have a lot of keys, this could take a LONG time.
import boto
def bucket_du(bucket_name):
s3 = boto.connect_s3()
bucket = s3.lookup(bucket_name)
total_bytes = 0
for key in bucket:
@quiver
quiver / README.md
Last active April 3, 2024 15:47
Who says PostgreSQL can't Pub/Sub like Redis?

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 5, 2023 21:58
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add git@github.com:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.

@ju-popov
ju-popov / timestamp.py
Last active April 7, 2021 16:09
Python DateTime / Timestamp Convertion
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
from tzlocal import get_localzone
local_tz = get_localzone()
local_dt = datetime.now(local_tz)
@hernantz
hernantz / common_fabfile.py
Last active July 14, 2017 06:00
Fabfile with common fabric tasks, featuring virtualenvwrapper, nginx, supervisord, git deployment and some other goodies.
from fabric.api import task, local, sudo, run, prefix, env, cd
from fabric.contrib.files import exists, first
from contextlib import contextmanager, nested
def once(s):
"""Command_prefixes is a list of prefixes"""
if s not in env.command_prefixes:
return s
return 'true'
@mplewis
mplewis / flask-uwsgi-nginx-primer.md
Last active October 24, 2022 19:20
Flask + uWSGI + nginx Primer. I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

Flask + uWSGI + nginx Primer

I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

How this shit works

  • Flask is managed by uWSGI.
  • uWSGI talks to nginx.
@sergiotapia
sergiotapia / md5-example.go
Last active December 5, 2023 03:53
Golang - How to hash a string using MD5.
import (
"crypto/md5"
"encoding/hex"
)
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
@ah-cog
ah-cog / Using the Terminal to Upload an Arduino Sketch to the Teensy 3.1.md
Last active April 16, 2020 01:00
Upload to the Teensy 3.1 from Terminal on OS X with Arduino 1.6.1 and Teensyduino 1.21.

Uploading Arduino Sketches to the Teensy 3.1 from the Terminal

First, install Arduino 1.6.1 from http://arduino.cc/en/Main/Software. I followed the Mac OS X for Java 6 link to download arduino-1.6.1-macosx.zip. Install Arduino by unzipping the Arduino file and moving it to /Applications/Arduino. Open Arduino to make sure it works and so it can finish setting up the environment for use. Next, install Teensyduino 1.21 from https://www.pjrc.com/teensy/td_download.html. I followed Macintosh OS-X Installer to download teensyduino.dmg. Open and proceed through the Teensyduino installer, and when prompted to locate Arduino, select /Applications/Arduino, then continue to the next step in the installer.

At this point, you should be ready to upload a sketch. Follow the instructions below.

To upload from the terminal, enter the following command:

/Applications/Arduino.app/Contents/MacOS/JavaApplicationStub --board teensy:avr:teensy31 --port /dev/tty.usbmodem573061 --upload /Users/mokogobo/Checkout
@max-mapper
max-mapper / readme.md
Last active May 21, 2022 11:02
ffmpeg youtube live event rtmp stream from raspberry pi with raspi camera (raspivid)
  1. compile ffmpeg for arm https://github.com/fiorix/ffmpeg-arm
  2. create youtube 'live event'. get rtmp url + session id
  3. run this:
raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<SESSION>

you can tweak -b and -fps to your liking. the settings above work well for 1080p. by not specifying width or height we get the full 1920x1080 resolution from the raspi camera

@masahirosuzuka
masahirosuzuka / .gitignore
Last active March 10, 2019 14:46
gitignore template for KiCad project
# temp files
*.bak
*.bck
*.kicad_pcb-bak
*-cache.lib
# *-rescue.lib
ftp-lib-table
# for external tools
*.dsn