Skip to content

Instantly share code, notes, and snippets.

@agirorn
agirorn / custom-matcher-compackt.js
Last active April 24, 2017 12:37
Custom Jasmine Matcher
var customMatchers = {
toBeGoofy: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
if (expected === undefined) {
expected = '';
}
var result = {};
result.pass = util.equals(actual.hyuk, "gawrsh" + expected, customEqualityTesters);
@agirorn
agirorn / linux-beep.sh
Created March 1, 2016 13:27
Beep command for Linux ( Ubuntu desktop ).
#!/usr/bin/env bash
( speaker-test -t sine -f 1000 )& pid=$! ; sleep 0.2s ; kill -9 $pid
@agirorn
agirorn / dump-pagages.sh
Created May 27, 2016 10:54
Dump/Restore installed packages
dpkg --get-selections > ~/installed_libs.txt
@agirorn
agirorn / Promise.js
Created November 18, 2016 10:44
How do I return the response from an asynchronous call.....
function foo() {
return new Promise(function(resolve) {
$.ajax({
url: '...',
success: function(response) {
resolve(response); // Returning the response
}
});
});
}
@agirorn
agirorn / dec-2-hex-string.js
Created November 23, 2016 16:04
Convert decimal to hex in JavaScript.
function dec2hexString(dec) {
return '0x' + (dec+0x10000).toString(16).substr(-4).toUpperCase();
}
@agirorn
agirorn / kill-all.zsh
Created June 14, 2017 15:45
Kill all processes by name
# kill-all <NAME>
function kill-all() {
ps aux | grep $1| grep -v grep | awk '{print $2}'|xargs kill -s 9
}
@agirorn
agirorn / check-if-var-is-set.sh
Created July 6, 2017 09:32
Bash: Check if variable is set.
#!/usr/bin/env bash
# Uncomment next line to test
# VARIABLE=10
if [ -z ${VARIABLE+x} ]; then
echo "Variable \$VARIABLE is not set"
else
echo "Variable \$VARIABLE is set and has the value of => $VARIABLE"
fi
@agirorn
agirorn / track-pad.sh
Last active July 6, 2017 10:23
Disable or enable the TrackPad on an IBM T450 laptop for Ubuntu.
#!/usr/bin/env bash
showHelp() {
cat <<HELP
$0 [OPTIONS]
Enable or Disable the trackpad on T450 on Ubuntu.
Options:
-h, --help Print help screen
@agirorn
agirorn / to-old-bmp.sh
Last active November 8, 2017 18:45
Use graphicsmagick to convert image to old BMP format
#!/usr/bin/env bash
convert image.png ppm:- | convert ppm:- BMP3:image.bmp
@agirorn
agirorn / unhandled-rejection.js
Last active February 1, 2021 21:24
Unhandled promise rejection warning with a stack trace
/*
* You can also just do "node --trace-warnings app.js"
*/
process.on('unhandledRejection', (rejection) => {
console.log('Unhandled promise rejection warning:');
console.log(rejection);
});