-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
63 lines (49 loc) · 1.55 KB
/
.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
function homestead() {
(cd ~/Homestead && vagrant $*)
}
# IP geolocation data
function ipinfo() {
curl -w "\n" http://ipinfo.io/"$1"
}
# Simple desktop capture
function capture() {
local output=$1
# Generate a file name if none is provided
if [[ -z $output ]]; then
output=capture-$(date +%FT%H_%M_%S).webm
fi
local resolution=$(xrandr | grep -m 1 "*" | grep -Po '\d+x\d+')
local tmp=$(mktemp -u tmp.XXXX.mkv)
# Capture full screen to a temp file. This is a lossless encoding to
# avoid dropping frames.
echo "Capturing screen. Press [q] to stop."
ffmpeg -video_size "$resolution" -framerate 30 -f x11grab -i "$DISPLAY"\
-c:v libx264 -qp 0 -preset ultrafast -loglevel error "$tmp"
# Re-encode the lossless capture and save to output.
echo "Encoding $output..."
ffmpeg -i "$tmp" -c:v libvpx-vp9 -crf 50 -b:v 0 -threads 4 -loglevel error "$output"
rm "$tmp"
}
# Convenient calculation
function calc() {
echo "$@" | bc -l
}
# Adds latency and packet loss to eth0.
# For when you network is simply too fast.
function slowmode() {
local delay=${1:-200}
local loss=${2:-20}
# Find the defualt network interface
local iface=$(route | grep '^default' | grep -o '[^ ]*$')
# Apply network latency and packet loss
sudo tc qdisc add dev "$iface" root netem loss "$loss%" delay "${delay}ms" 10ms 25%
# Make sure to disable it again on exit
trap "sudo tc qdisc del dev $iface root; echo; return" SIGINT SIGTERM
echo "Slow mode enabled"
echo "Press ctrl-c to disable slow mode"
# Do nothing until we exit
while true; do
sleep 60
done
}