Skip to content

Instantly share code, notes, and snippets.

View pcting's full-sized avatar

Patrick Ting pcting

View GitHub Profile
@pcting
pcting / pactl-compact-list-sinks.sh
Last active September 1, 2022 16:44
PulseAudio Bash Helpers
#!/bin/sh
pactl list sinks | grep --color=never -E '(^Sink|Name|device.description)' | sed 's/^Sink #//g' | sed -r 's/Name: //g' | sed -r '/[[:digit:]]$/{N;s/\n//}' | sed -r '/_sink$/{N;s/\n//}' | sed 's/\t\tdevice.description = /\t/g'
@pcting
pcting / backlight.sh
Last active July 29, 2022 22:57
backlight script for Lenovo ThinkPad P15s Gen 2i
#!/bin/bash
# Example: increae brightness by 15%
# backlight.sh inc 15
CURRENT_BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/brightness)
MAX_BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/max_brightness)
ONE_PERCENT_FACTOR=$(( MAX_BRIGHTNESS / 100 ))
@pcting
pcting / generate_ips.sh
Created November 17, 2020 19:30
generate a range of ips
#!/bin/sh
for IP in $(nmap -n -sL 10.8.9.10-50 | awk '{print $5}' | grep --color=never '^[0-9]'); do
echo $IP
done
@pcting
pcting / cgroup-chrome.sh
Last active November 29, 2017 08:09
limit chrome memory
#!/bin/sh
cgcreate -a $USER -s 666 -g swap,memory:chrome
cgset -r memory.limit_in_bytes=4G -r memory.soft_limit_in_bytes=3800M -r memory.swappiness=5 chrome
cgexec -g memory:chrome /opt/google/chrome/google-chrome
@pcting
pcting / AkkaHttpCorsSupport.scala
Last active August 2, 2018 13:44
Akka HTTP 1.0 CORS Support
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Credentials`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Methods`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Origin`
import akka.http.scaladsl.model.headers.Origin
import akka.http.scaladsl.server.Directive0
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.MethodRejection
@pcting
pcting / gist:1041387
Created June 22, 2011 22:13
SSH Tunnel UDP Packets from REMOTE server
# YOUR LOCAL BOX
socat -t0 -T0 tcp4-listen:6667,reuseaddr,fork UDP:localhost:4445
ssh user@remote_server -R 6667:localhost:6667
# REMOTE MACHINE
socat -t0 -T0 udp4-recvfrom:4445,reuseaddr,fork tcp:localhost:6667
@pcting
pcting / gist:1026203
Created June 14, 2011 23:44
Chainsaw Configuration for Log4r
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">
<param name="Port" value="4445" />
</plugin>
<logger name="org.apache.log4j">
<level value="warn"/>
</logger>
<root>
@pcting
pcting / install-rails-ruby-1.9.2.sh
Created June 7, 2011 20:06 — forked from dmitry-ilyashevich/install-rails-ruby-1.9.2.sh
Installing rails on rvm ruby 1.9.2
#!/bin/bash
# created by Josh Frye | [email protected]
# Check if the user has sudo privileges.
sudo -v >/dev/null 2>&1 || { echo $(whoami) has no sudo privileges ; exit 1; }
# Update the system before going any further
echo "Updating system..."
sudo apt-get update >> install.log && sudo apt-get -y upgrade >> ~/install.log
echo "done.."
@pcting
pcting / gist:895304
Created March 30, 2011 21:05
Generate CSSH commands from hostnames generated by elb-describe-instance-health
#!/bin/sh
LB_HEALTH=$(elb-describe-instance-health 'my-elb-name')
echo "$LB_HEALTH"
LB_NAME=$(echo "$LB_HEALTH" | awk 'BEGIN { ORS=" " } { print $2 }')
echo "$LB_NAME"
INST_CMD=$(echo "$LB_NAME" | awk '{ print "ec2-describe-instances " $0 }')
echo "$INST_CMD"
INST_HEALTH=$(eval "$INST_CMD")
echo "$INST_HEALTH"
@pcting
pcting / gist:877729
Created March 19, 2011 19:18
CPAN for Ganglia Python Module
curl http://github.com/api/v2/json/blob/all/ganglia/gmond_python_modules/master