Skip to content

Instantly share code, notes, and snippets.

Avatar
🅱️
'sup

Raj Perera rajiteh

🅱️
'sup
  • @ubisoftinc
  • Toronto, ON
View GitHub Profile
View tall-merge-psd.js
const ZERO = new UnitValue(0, 'px')
function appendToDoc(dstDoc, fileRef, isFirstDoc) {
const srcDoc = app.open(fileRef, undefined, true);
superSelect()
superCopy()
const dstDocWidth = new UnitValue(dstDoc.width.as('px') < srcDoc.width.as('px') ? srcDoc.width.as('px') : dstDoc.width.as('px'), 'px')
const dstDocHeight = new UnitValue(isFirstDoc ? srcDoc.height.as('px') : dstDoc.height.as('px') + srcDoc.height.as('px'), 'px')
const pasteTopLeftRightBottom = isFirstDoc ? [ZERO, ZERO, dstDocWidth, dstDocHeight] : [new UnitValue(dstDoc.height.as('px'), 'px'), ZERO, dstDocWidth, dstDocHeight]
View settings.json
// This file was initially generated by Windows Terminal 1.1.2021.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@rajiteh
rajiteh / prometheus-repl.sh
Created Feb 14, 2018
because prometheus ui is terrible
View prometheus-repl.sh
#!/bin/bash
export PROMETHEUS_SERVER="http://prometheus-server.example.com"
# install prometheus-query from https://github.com/ryotarai/prometheus-query
# $ go get -u github.com/ryotarai/prometheus-query
while IFS="" read -r -e -d $'\n' -p 'query> ' query; do
history -s "$query"
prometheus-query -start "1 minute ago" -query "$query" --format tsv | column -t
echo "---"
View copy_status.sh
#!/bin/bash
## ./script path1 path2
src=$1
dst=$2
function percentage {
jq -n "$(du -s $1 | cut -f1)/$(du -s $2 | cut -f1)*100"
}
cat last_check || :
@rajiteh
rajiteh / logger.sh
Last active Aug 14, 2017
Colourful Bash
View logger.sh
#!/bin/bash
[ -z "${LOGGING_NO_COLORS}" ] && [ -t 1 ] && [ -n "$(tput colors)" ] || LOGGING_NO_COLORS="TRUE"
log() {
local color=$1;shift
local msg="$(date +%T.%3N) ${BASH_SOURCE[2]##*/}[${BASH_LINENO[1]}]: ${@}"
local reset="\e[0m"
if [ -n "${LOGGING_NO_COLORS}" ]; then
color="";reset=""
fi
@rajiteh
rajiteh / update-check.sh
Created Jul 26, 2017
Ghetto Docker Update
View update-check.sh
#!/bin/sh
RUNNING="$(docker ps --format "{{ .ID }}" | xargs docker inspect --format "{{ .Image }}" | xargs docker inspect --format "{{ .Id }} {{ .RepoTags }}")"
AVAILABLE="$(docker images --format "{{ .ID }} [{{ .Repository }}:{{ .Tag }}]" --no-trunc)"
NEEDS_UPDATE=0
echo "${RUNNING}" | while read line; do
current_id=$(echo "${line}" | awk '{print $1}')
current_tag=$(echo "${line}" | awk '{print $2}')
updated_id=$(echo "${AVAILABLE}" | grep -F "${current_tag}" | awk '{print $1}')
if [ "$current_id" != "$updated_id" ]; then
echo "Update required for ${current_tag}"
@rajiteh
rajiteh / mitmproxy_transparent_reverse_proxy.py
Created May 3, 2017
Sets up mitmproxy as a transparent reverse proxy to any upstream (as defined by the host header of the http packets)
View mitmproxy_transparent_reverse_proxy.py
#
# ./mitmproxy -U http://doesnt.matter -p 8001 -s mitmproxy_transparent_reverse_proxy.py
#
# HTTP_PROXY=http://localhost:8001 ./program_to_run
#
def request(flow):
if flow.request.method == "CONNECT":
return
if flow.live:
@rajiteh
rajiteh / 0_pr_status.1d.sh
Created Jan 30, 2017
bitbar citizenship canada timers and status
View 0_pr_status.1d.sh
#!/bin/bash
PATH=$PATH:/usr/local/bin/
WORK_DIR=~/.bitbar/pr_status
CHANGE_FILE="${WORK_DIR}/changed"
LOGGING=0
mkdir -p ${WORK_DIR}
function errcho {
if [ "${LOGGING}" != "0" ]; then
@rajiteh
rajiteh / tcpserver.sh
Created Sep 7, 2016
Simple TCP listener
View tcpserver.sh
while true; do echo "HELLO FROM THE OTHER SIDE" | perl -MIO::Socket::INET -ne 'BEGIN{$l=IO::Socket::INET->new(LocalPort=>31337,Proto=>"tcp",Listen=>5,ReuseAddr=>1);$l=$l->accept}print $l $_';done
@rajiteh
rajiteh / switch-rancheros-docker.sh
Last active Aug 1, 2016
RancherOS docker version updater.
View switch-rancheros-docker.sh
#!/bin/bash
# RancherOS docker version updater.
# Author: @rajiteh
# License: BSD
#
# How to use:
# You need to use a persistent console (tested on ubuntu).
# Set up the script to be called at console initalization time.
#
# Example cloud-config.yml usage.