Skip to content

Instantly share code, notes, and snippets.

View ajpen's full-sized avatar

Anfernee Jervis ajpen

View GitHub Profile
@ajpen
ajpen / virtualenv-auto-activate.sh
Last active May 7, 2018 16:14 — forked from Willyfrog/virtualenv-auto-activate.sh
virtualenv-auto-activate-auto-deactivate with support for existing custom PROMPT_COMMAND
#!/bin/bash
_virtualenv_auto_activate() {
if [ -e ".env" ]; then
# Check to see if already activated to avoid redundant activating
if [ "$VIRTUAL_ENV" = "" ]; then
source .env/bin/activate
fi
else
if [ "$VIRTUAL_ENV" != "" ]; then
@ajpen
ajpen / log_configuration_sample.conf
Created April 10, 2018 21:23
Separates Supervisor logs by process and passes them to handlers specified by a python's logging module configuration file.
[formatter_form01]
format=F1 %(asctime)s %(levelname)s %(message)s
datefmt=
class=logging.Formatter
[handler_hand01]
class=pygelf.GelfHttpHandler
level=NOTSET
args=('dockerhostip', 12201, False)
@ajpen
ajpen / interval.go
Created April 10, 2018 20:58
Interval is a wrapper for the ticker and tick functions in the time library. It wraps everything into a single function call. The function passed is executed in a goroutine and should prepared as such. All intervals started will spawn a goroutine in the background, which will be responsible for tracking the ticks and starting the tasks. This pre…
// Package interval runs functions(tasks) at specific intervals, wrapping the standard library ticker, Tasks should be designed as goroutine compatible
package interval
import (
"time"
"errors"
)
from flask import Flask
from background import data_valid, process
app = Flask(__name__)
@app.route("/")
def hello():
data = request.args.to_dict()
if data_valid(data):
@ajpen
ajpen / commonrc
Created October 29, 2017 01:32
bash kit commands
# Kills a process by its name
killname () {
ps aux | grep -v grep | grep -m 1 "$1" | awk '{print $2}' | xargs kill 15
}
# Kills the process listening to port number given
@ajpen
ajpen / visorlognotes.md
Last active February 27, 2017 15:16
Things observed when writing visorlog
  • Docker containers can only communicate with the host using the docker0 interface address, which from my understanding is the network bridge. The cleanest way of doing this is through the 'hosts' file. the IP can be taken running this command on a linux host: ip route list dev docker0 | awk 'NR==1 {print $NF}'. If it does not work, changing NR==1 to NR==2 may do the job. This can be added as an ENV variable for easily access. To add a new entry to the hosts file you need to add the --add-host= argument to your docker run command. e.g. docker run --add-host=hostip:$DOCKER_HOST_IP...

Python logging using YAML configuration is greatly limited. Its better to use the dict config if you wish to support custom handlers, etc. the YAML config can only get handlers that are in the current namespace. Which means, if you want to use any of the typical python handlers, you need to do import logging.handlers in the module that configures the logging from the YAML file which sucks. Use the dict config!

@ajpen
ajpen / vimrc
Last active October 20, 2016 10:27
My vimrc setup
"" Minimal setting and configuration
"" These settings makes editing less of a drag :)
"---------------------------------------------------------------------------------
" Use vim settings
set nocompatible
" changes backspace indentation behavior
set backspace=indent,eol,start
# install openjdk-7
sudo apt-get purge openjdk*
sudo apt-get -y install openjdk-7-jdk
# Install elasticsearch
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo update-rc.d elasticsearch defaults 95 10
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 9200, guest: 9200
config.vm.provider "virtualbox" do |v|
v.memory = 4000
v.cpus = 2
v.name = "ES-2.4"
end
end
/* ---------------------------------------
* File: filecpy.cpp
* Usage: ./filecpy source destination
* ---------------------------------------
* Function: Copies the source file to
* the new file specified by the path
* called destination. The program
* creates the new file and then copies
* the contents of source to it.
* _______________________________________