Skip to content

Instantly share code, notes, and snippets.

View hparadiz's full-sized avatar
💻
Coding

Henry Paradiz hparadiz

💻
Coding
View GitHub Profile
@hparadiz
hparadiz / better-spotify-linux-launcher.sh
Created May 26, 2022 04:32
Properly handles passing a Spotify URI to a running instance of spotify via DBUS
#!/bin/bash
# check if spotify is already running and if so just pass the uri in
if pgrep -f "Spotify/[0-9].[0-9].[0-9]" > /dev/null
then
busline=busline=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri $1
echo "Spotify is already running"
echo "Sending ${busline} to dbus"
if command -v qdbus &> /dev/null
then
qdbus $busline
@hparadiz
hparadiz / canonicalize.js
Created March 2, 2021 07:40
JavaScript <-> PHP compatible JSON canonicalizer
var canonicalize = function(input) {
if (input === null || typeof input !== 'object') {
/////////////////////////////////////////////////
// Primitive data type - Use ES6/JSON //
/////////////////////////////////////////////////
return JSON.stringify(input);
} else if (Array.isArray(input)) {
/////////////////////////////////////////////////
// Array - Maintain element order //
@hparadiz
hparadiz / chromium-linux-meta-modifier-key.patch
Last active August 29, 2020 23:58
Have the modifier key for shortcuts use Meta instead of Ctrl, based on Chromium tagged release 84.0.4147.105
diff --git a/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc b/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
index 4995b3c75c44..a4014f0482c5 100644
--- a/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
+++ b/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
@@ -140,39 +140,39 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId(
return true;
case IDC_CONTENT_CONTEXT_UNDO:
- *accel = ui::Accelerator(ui::VKEY_Z, ui::EF_CONTROL_DOWN);
+ *accel = ui::Accelerator(ui::VKEY_Z, ui::EF_PLATFORM_ACCELERATOR);
@hparadiz
hparadiz / keybindings.json
Created August 11, 2020 05:47
VSCode Key Bindings for Linux to use Meta+ instead of Ctrl+ for most common shortcuts
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "meta+c",
"command": "editor.action.clipboardCopyAction"
},
{
"key": "meta+x",
"command": "editor.action.clipboardCutAction"
},
@hparadiz
hparadiz / backup.php
Created August 3, 2020 07:01
PHP Database Backup with SSH Tunneling
#!/usr/bin/env php
<?php
require_once(getenv('PHP_LIBS_AUTOLOADER'));
(new \NunoMaduro\Collision\Provider)->register();
class Config extends BackupManager\Config\Config
{
public static function fromArray(array $array)
{
return new static($array);
}
<?php
/**********************************************************/
/* HTML PURIFICATION */
/**********************************************************/
/* string purify
*
* @param $dirty_html string
* @param $lite bool Disallow everything except u,l,i,h1,h2,h3,h4,h5,h6,strong,em,span,div; Also disallow style/class
* @param $customize bool
@hparadiz
hparadiz / poe_tcp_kill.sh
Created June 20, 2020 07:25
Force TCP Reset for PathOfExile_x64Steam.exe in GNU/Linux
#!/bin/sh
POEPID="$(ps -A -o pid,cmd|grep PathOfExile_x64Steam.exe | grep -v grep |head -n 1 | awk '{print $1}')"
POECONNECTION="$(lsof -np $POEPID | grep IPv4 | awk '{print $4}' | tail -n 1 | sed 's/u//g')"
GDBCOMMAND="call (int)close($POECONNECTION)"
POEIP="$(lsof -np 19380 | grep IPv4 | tail -n 1 | awk '{print $9}' | awk -F\> '{print $2}' | awk -F: '{print $1}')"
tcpkill host $POEIP &
sleep 2
for child in $(jobs -p); do
echo kill "$child" && kill "$child"
done
@hparadiz
hparadiz / hubot.sh
Created June 5, 2020 00:17
Daemon wrapper for hubot written in bash
#!/bin/bash
set -e
# detect our real working directory through symlinks
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
@hparadiz
hparadiz / chartjs-node-test.js
Created June 1, 2017 14:50
Test for chartjs-node npm module which checks if a file is ready after writing
const ChartjsNode = require('chartjs-node');
const fs = require('fs');
const tmp = require('tmp');
charts = {
drawLineChart: function(options,onFinish) {
var width = options.width ? options.width : 700;
var height = options.height ? options.height : 400;
delete options.width, options.height;
@hparadiz
hparadiz / register_globals.php
Last active June 1, 2017 15:20
A function which simulates the register_globals setting from PHP <=5.3 for PHP >=5.4
<?php
/* A function which simulates the register_globals setting from PHP <=5.3 for PHP >=5.4
* Blasphemy I know. Just an example of named functions detailed in https://php.net/manual/en/language.variables.variable.php
*/
function register_globals($Order = 'EGPCS')
{
$register_globals = function(array &$GlobalArray)
{
foreach($GlobalArray as $Variable=>$Value)
{