Skip to content

Instantly share code, notes, and snippets.

View catichenor's full-sized avatar

Christopher Tichenor catichenor

View GitHub Profile
@catichenor
catichenor / scaledown_xrandr.sh
Last active August 6, 2016 02:26
How to scale down a larger display to a smaller display via xrandr with both connected simultaneously
xrandr --output LVDS-0 --mode 1920x1080 --output VGA-0 --mode 1024x768 --same-as LVDS-0 --scale 1.875x1.40625 #Scale down the 1920x1080 resolution of an LVDS display and display it on a 1024x768 VGA display.
# Scaling one display from 1024x768 to 1920x1080: xrandr --output LVDS-0 --scale 1.875x1.40625
# Multiple for scaling 1280x1024 to 1920x1080: 1.5x1.0546875
@catichenor
catichenor / jsonParse_enquoteJSONProperty.js
Last active January 19, 2016 23:23
Convert JavaScript object string to something that can be parsed by JSON
unquotedPropertyString = '{obj_One: "Hello", obj_Two: "World!"}'; //Mixing camelCase and snake_case. It's a test. Sue me.
// brokenParse = JSON.parse(unquotedPropertyString); //Error! Why is obj_One not quoted?!?!?!
quotedPropertyString = unquotedPropertyString.replace(/([A-Za-z0-9_]+):/g, '\"$1\":'); //Result: '{"obj_One": "Hello", "obj_Two": "World!"}'
// * The above won't work if you're not using alphanumeric characters or underscores for your object property names.
// ** The regex will also have some false positives if your property values have colons in them. You'll need to adjust the regex for your purposes.
// For me, I needed to process output from the Node.js "formidable" module, which prints each property line-by-line, so I used output.replace(/([\s|\{]) ([A-Za-z0-9_]+): \"/g, '$1 \"$2\": \"')
// I also needed to fix the single quotes around property value from the formidable output, but that doesn't apply to this example.
workingParse = JSON.parse(quotedPropertyString); //Yay! It works!* **
@catichenor
catichenor / jsonParse_removeTrailingComma.js
Last active February 25, 2016 00:32
Turns an standard Javascript array into a JSON object array
exampleArray = [ "Hello", "World", "foo", "bar", "generic", "example", "recuerdos", "a todos" ];
objText = "";
for (i = 0, len = exampleArray.length; i < len; i++) {
thisResult = exampleArray[i];
objText += '"obj_' + i + '": "' + thisResult + '", '; // First time this loops will result in --"obj_0": "Hello", --
}
// objText should now be --"obj_0": "Hello", "obj_1": "World", "obj_2": "foo", "obj_3": "bar", -- etc., but this string ends with a comma, which JSON.parse won't allow.
@catichenor
catichenor / averagePerformance.sh
Last active February 25, 2016 00:34
How to average the performance results of several runs on a particular command in Bash
#!/bin/bash
numberOfRuns="10"
i="0"
while [ $i -lt ${numberOfRuns} ]
do
results[${i}]=`./performanceTest` # Replace ./performanceTest with the command line of the test you want to run.
# ^ This assumes that the result of the test will be a number (integer or decimal).
@catichenor
catichenor / compareImages.sh
Last active March 5, 2016 21:40
Compare two images and return whether or not they match
#!/bin/bash
THRESHOLD="15000" # You'll need to do some testing to come up with this number.
# Requires ImageMagick, also using PNG format since JPEG adds too much noise
echo "`compare -metric RMSE clean_webcam_image.png corrupt_webcam_image.png NULL: 2>&1 | awk '{print $1}'` > ${THRESHOLD}" | bc # Returns 1 if the difference is greater than 15000, 0 otherwise
@catichenor
catichenor / killGunicorn.sh
Last active March 25, 2016 22:21
How to kill a bunch of gunicorns in one line
#!/bin/bash
# How to kill a bunch of gunicorns in one line
ps aux | grep gunicorn | awk '{print $2}' | sudo xargs kill -9
# And no, `pkill -9 gunicorn` doesn't work because it kills out of sequence and causes a crash.
@catichenor
catichenor / untarUnzip_all.sh
Last active May 3, 2016 21:40
Unzip and untar all files in the current directory
#!/bin/bash
find . -name "*.tar.gz" -maxdepth 1 -exec tar -zxvf {} \; # untar/ungzip all archives in the current directory
# find . -name "*.tar.bz2" -maxdepth 1 -exec tar -vxjf {} \; # Do the same for .tar.bz2 files
@catichenor
catichenor / aptSearchMultiple.sh
Created May 11, 2016 01:04
Search for multiple packages in apt at the same time
#/bin/bash
# Example: Look for dependencies for https://github.com/ToolsOnAir/gl-frame-bender
echo "cmake boost protobuf glfw glm devil" | tr ' ' '\n' | xargs -I '{}' apt search '{}' # apt warns against this, but you can redirect output to a file if needed.
@catichenor
catichenor / pomodoroTimer.sh
Last active July 28, 2016 18:44
A simple Pomodoro timer for GNOME 3
#!/bin/bash
# Work for 25 minutes, break for 5 minutes.
while [ TRUE ]; do
echo "Worktime: The time is `date +%l:%M`"
notify-send "Work" "Time to start working."
sleep 1200
echo "Worktime: 5 minutes left. The time is `date +%l:%M`"
notify-send "Work" "5 minutes left."
@catichenor
catichenor / yumPrettyGroupList.sh
Last active January 17, 2017 21:39
Write out pretty/long group names in a package group from yum
#!/bin/sh
# I would hope there's a more elegant way of doing this directly in yum/DNF, but I couldn't find one.
yum group info "Development and Creative Workstation" | grep "\+" | sed 's/ +\+//g' | xargs yum group info | grep "Group:" | sed 's/.*Group: //g' > prettyGroupNames.txt
# Replace "Development and Creative Workstation" with your package group of choice.
# Untested in DNF