Skip to content

Instantly share code, notes, and snippets.

View ajpen's full-sized avatar

Anfernee Jervis ajpen

View GitHub Profile
@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 / 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
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 / 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"
)
@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 / 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 / configuration.nix
Last active July 24, 2020 04:23
Nixos setup for XPS machine
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
For finding the nearest edge to a parking meter:
https://stackoverflow.com/questions/55522641/how-can-i-get-the-start-and-end-node-of-the-nearest-edge-to-large-points-faster
@ajpen
ajpen / clean_browser.txt
Created July 31, 2020 23:53
browser without addressbar, etc
For chrome/chromium it is the --app=http://address.com flag.
You would use it by calling chromium-browser --app=http://some.website.org or google-chrome --app=http://www.google.com or chrome.exe --app=http://you.get.it etc.
All available switches: http://peter.sh/experiments/chromium-command-line-switches/
EDIT: You might also want to take a look at the --kiosk flag.
@ajpen
ajpen / cheatsheet.md
Created August 6, 2020 19:14
pandas cheatsheet

WHERE clause equivalent on dataframe

df[df['column_name'] == 'what to search for']

With AND and OR logical operators: df[df[('column_name'] == 'what to search for') & ('column_name'] == 'what to search for')]

df[df[('column_name'] == 'what to search for') | ('column_name'] == 'what to search for')]

LIKE clause equivalent

df[df['column_name'].str.contains('substring to look for')]