Skip to content

Instantly share code, notes, and snippets.

View jamesalbert's full-sized avatar
🐐
Working from home

James Albert jamesalbert

🐐
Working from home
  • Antioch, CA
View GitHub Profile
@jamesalbert
jamesalbert / install_csim.sh
Last active February 2, 2017 00:58
install csim for java
wget -O /tmp/csimForJava.jar.zip http://www.ics.uci.edu/~wayne/courses/cs115/CSIM/csimForJava.jar.zip;
export DIR=$JAVA_HOME
if [ -f /usr/libexec/java_home ]
then
DIR=$(/usr/libexec/java_home)/jre
fi
sudo unzip -n /tmp/csimForJava.jar.zip -d $DIR/lib/ext;
sudo chmod 644 $DIR/lib/ext/csimForJava.jar
echo "csimForJava.jar has been placed in $DIR/lib/ext"
@jamesalbert
jamesalbert / install_bats.sh
Created April 25, 2017 20:35
install the bash testing framework bats on linux
#!/usr/bin/env bash
read -p "Where do you want to install bats? [~/.local] > " batspath
if [[ -z "$batspath" ]]; then
batspath="$HOME/.local"
fi
cd $HOME
git clone https://github.com/sstephenson/bats.git
@jamesalbert
jamesalbert / test.bats
Last active May 2, 2017 05:01
test hw3 part 2
#!/usr/bin/env bats
if [ -z $TRASH ]; then
echo '$TRASH must be defined'
exit 1
fi
trashdir=$TRASH
function finish {
trash > /dev/null
@jamesalbert
jamesalbert / chext.sh
Last active June 4, 2017 05:02
change the extension of multiple files
function chext {
for f in *.$1; do
mv -- "$f" "${f%.$1}.$2";
done;
}
# example changing all files *.jpeg to *.jpg: chext jpeg jpg
#!/usr/bin/env bash
function usage {
echo "view-log <status-regex> [--pull]"
exit 1
}
[[ "$1" == "" ]] && usage || filter=$1
[[ ! -d ~/.awslogs ]] && mkdir ~/.awslogs
@jamesalbert
jamesalbert / serializers.py
Created July 31, 2018 20:04
Django AuthTokenSerializer that requires only an email and password (instead of username).
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from rest_framework.compat import authenticate
class AuthTokenSerializer(serializers.Serializer):
email = serializers.CharField(label=_("Email"))
password = serializers.CharField(
label=_("Password"),
@jamesalbert
jamesalbert / urls.py
Created July 31, 2018 20:09
default auth
from django.urls import re_path
from rest_framework.authtoken.views import obtain_auth_token
urlpatterns = [
re_path(r'^api-token-auth/$', obtain_auth_token)
]
@jamesalbert
jamesalbert / urls.py
Created July 31, 2018 20:12
custom auth
from django.urls import re_path
from rest_framework.authtoken.views import ObtainAuthToken
from .serializers import AuthTokenSerializer
ObtainAuthToken.serializer_class = AuthTokenSerializer
obtain_auth_token = ObtainAuthToken.as_view()
urlpatterns = [
re_path(r'^api-token-auth/$', obtain_auth_token)
]
#!/usr/bin/env bash
set -uo pipefail
# set -x
PATH=$PWD/bin:$PATH
RUST_HOME=$HOME/docker-rust
SYSV=$(pidof /sbin/init >/dev/null && echo "yes" || echo "no")
SYSD=$(pidof systemd >/dev/null && echo "yes" || echo "no")
@jamesalbert
jamesalbert / check.py
Last active December 8, 2022 23:29
quick script to compile a list of nodes that are failing plans on nomad clients
import requests
import json
import os
url = "https://grafana.rbx.com"
headers = {
"Authorization": "Bearer " + os.environ["GRAFANA_TOKEN"],
"Accept": "application/json",
"Content-Type": "application/json",