Skip to content

Instantly share code, notes, and snippets.

[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
[policy_effect]

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@aslamhadi
aslamhadi / paypal_fee.py
Last active April 14, 2018 08:04
Simple script to calculate Paypal fee
#!/usr/bin/env python
import sys
from math import ceil
def ceil_two_digits(amount):
return (ceil(amount * 100) / 100.0)
def calculate_invoice(invoice_amount):
@aslamhadi
aslamhadi / backup.sh
Last active January 17, 2024 11:37
Shell script to dump mysql db and upload it to Back Blaze
#!/bin/bash
DB_NAME=""
DB_PASSWORD=""
DB_USER=""
DB_HOST=""
TODAY_DATE="$(date +'%d_%m_%Y_%H_%M_%S')"
FILENAME="$DB_NAME$TODAY_DATE".gz
BACKUP_DIR="/home/aslam/backup/$FILENAME"
@aslamhadi
aslamhadi / install-kafka.txt
Last active January 26, 2018 03:52 — forked from jarrad/install-kafka.txt
Install Kafka on OSX via Homebrew
$> brew cask install java
$> brew install kafka
$> vim ~/bin/kafka
# ~/bin/kafka
#!/bin/bash
zkServer start
kafka-server-start.sh /usr/local/etc/kafka/server.properties
@aslamhadi
aslamhadi / upgrade_wsl.md
Last active March 12, 2017 15:12
upgrade wsl to 16.04
  • sudo apt-get remove screen
  • sudo do-release-upgrade
  • (post-upgrade) sudo apt-get install screen

source: microsoft/WSL#927

@aslamhadi
aslamhadi / error_handler.py
Last active December 15, 2018 14:35
Custom error handler in DRF
from rest_framework.views import exception_handler
def custom_exception_handler(exc, context):
# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
if response is not None:
# check if exception has dict items
@aslamhadi
aslamhadi / remove-merged-branch
Created December 21, 2016 05:47
Remove merged branches in local
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
public class RestAuthorizeAttribute : AuthorizeAttribute
{
private const string SecurityToken = "token"; // Name of the header
private readonly IAuthApiService _authApiService = new AuthApiService();
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (Authorize(filterContext))
{
return;
@aslamhadi
aslamhadi / c3.js
Created August 17, 2016 12:12
x axis category c3js
var chart = c3.generate({
data: {
columns: [
['reject', 30, 200, 100, 400, 150, 250, 50, 100, 250],
['size', 40, 500, 400, 40, 15, 200, 50, 10, 600]
],
type: 'bar'
},
axis: {