Skip to content

Instantly share code, notes, and snippets.

@Nagasaki45
Nagasaki45 / conversions
Last active January 29, 2016 12:15
A cheatsheet of usefull conversion commands
# Convert FLAC to MP3 cheatsheet
find . -name "*.flac" -exec ffmpeg -i {} -acodec libmp3lame -ab 320k {}.mp3 \;
find . -name "*.flac.mp3" -exec rename flac.mp3 mp3 {} \;
find . -name "*.flac" -exec rm {} \;
# Speed up a video
./ffmpeg -i original.avi -b:v 5182k -filter:v "setpts=PTS/4" faster.avi
# Merge PDFs
pdfunite in-1.pdf in-2.pdf in-3.pdf out.pdf
@Nagasaki45
Nagasaki45 / .tmux.conf
Last active August 29, 2015 14:20
My .tmux.config
# Set prefix key to Ctrl-a
set -g prefix C-a
# Set vi mode
set-window-option -g mode-keys vi
setw -g mode-keys vi
# Send C-a to apps when presses twice
bind C-a send-prefix
@Nagasaki45
Nagasaki45 / game.py
Created July 23, 2015 06:36
Conway's Game of Life in python
import time
import numpy as np
ALIVE = 1
DEAD = 0
def grid_get_wrapped(grid, x, y):
height, width = grid.shape
x = x % width
@Nagasaki45
Nagasaki45 / using_command_line_arguments.py
Created October 31, 2015 19:51
Example for using command line arguments in python. Note that arguments are always string, so cast them to int / floats properly!
import sys
x = int(sys.argv[1])
y = int(sys.argv[2])
print('The result is', x + y)
# usage:
# python using_command_line_arguments.py 5 3
# The result is 8
@Nagasaki45
Nagasaki45 / dist.sh
Created October 31, 2015 19:57
A basic version of your script to run your code on the server. You can also parametrize the python script arguments. This way you will pass the arguments to the dist.sh script and it will pass them to your python script on the server.
scp /path/to/project/directory username@hostname:/path/to/project/on/the/server
ssh username@hostname "cd /path/to/project/on/the/server; python script.py arg1 arg2 arg3"
scp username@hostname:/path/to/project/on/the/server/results .
@Nagasaki45
Nagasaki45 / xteams-docker-compose-prod.yml
Created February 29, 2016 19:36
docker-compose configuration for Xteams production environment
nginx:
build: ./nginx
volumes_from:
- web
ports:
- "9768:8000"
links:
- web
restart: always
@Nagasaki45
Nagasaki45 / xteams-Dockerfile
Created February 29, 2016 19:39
Dockerfile of Xteams django app
FROM python:3.5.1
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pip install -r requirements/run.txt
ENV DJANGO_SETTINGS_MODULE xteams.settings.prod
RUN mkdir /staticfiles
RUN python manage.py collectstatic --noinput --clear
@Nagasaki45
Nagasaki45 / docker-compose-commands.sh
Created March 1, 2016 18:39
Building and running django app with docker-compose
# Build the three containers
# Images are automatically fetched, if necessary, from docker hub
docker-compose build
# Start a new web container to run migrations
# Use --rm to remove the container when the command completes
docker-compose run --rm web python manage.py migrate
# Run everything in the background with -d
docker-compose up -d
@Nagasaki45
Nagasaki45 / Xteams-internal-nginx.conf
Last active March 1, 2016 18:54
The Xteams Nginx container configuration file for serving static files from shared volume and passing other requests to the web container.
worker_processes 4;
events { worker_connections 1024; }
http {
server {
listen 8000;
location /static {
include mime.types;
@Nagasaki45
Nagasaki45 / Xteams-external-nginx.conf
Last active March 1, 2016 18:55
System wide Nginx configuration for Xteams
server {
listen 80;
server_name xteams.nagasaki45.com;
location / {
proxy_set_header Host xteams.nagasaki45.com;
proxy_pass http://localhost:9768;
}
}