Skip to content

Instantly share code, notes, and snippets.

@gboudreau
gboudreau / test-symlink-creation.php
Last active August 29, 2015 14:04
Test PHP symlink() function
@gboudreau
gboudreau / install-greyhole-package.sh
Last active April 5, 2020 13:20
Install Greyhole package
#!/bin/bash
# Detect package type from /etc/issue
_found_arch() {
local _ostype="$1"
shift
grep -qis "$*" /etc/issue && _OSTYPE="$_ostype"
}
# Detect package type
@gboudreau
gboudreau / install-ffmpeg-amazon-linux.sh
Last active November 21, 2023 19:48
How to compile ffmpeg on Amazon Linux (EC2)
#!/bin/sh
# Based on instructions found here: http://wiki.razuna.com/display/ecp/FFMpeg+Installation+on+CentOS+and+RedHat#FFMpegInstallationonCentOSandRedHat-InstallX264
if [ "`/usr/bin/whoami`" != "root" ]; then
echo "You need to execute this script as root."
exit 1
fi
cat > /etc/yum.repos.d/centos.repo<<EOF
@gboudreau
gboudreau / fix-google-drive-dark-mode-icons.sh
Created November 6, 2014 01:42
Fix Google Drive menuBar icon for dark mode
#!/bin/bash
function switch_files {
mv $1.png $1.tmp.png
mv $1-inverse.png $1.png
mv $1.tmp.png $1-inverse.png
mv $1@2x.png $1@2x.tmp.png
mv $1-inverse@2x.png $1@2x.png
mv $1@2x.tmp.png $1-inverse@2x.png
}
@gboudreau
gboudreau / test_checksum.php
Last active February 29, 2016 15:24
Calculate the MD5 checksum of a file over and over, clearing the disk cache between each read, to try to identify read errors that are happening on a hard drive. Ref: https://www.pommepause.com/2016/02/the-case-of-the-dying-hard-drive-that-flipped-bits/
<?php
$file = '/mnt/hdd5/persistent-app-data/downloading/vvgoor1586DSFGKL.part10.rar';
while (TRUE) {
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'");
$data1 = file_get_contents($file);
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'");
$data2 = file_get_contents($file);
@gboudreau
gboudreau / fix_files.php
Last active February 29, 2016 15:24
Script to fix files copied from a dying hard drive that would sometimes read bytes as 0x10 less than what they are. Ref: https://www.pommepause.com/2016/02/the-case-of-the-dying-hard-drive-that-flipped-bits/
<?php
/**
* Use this script to check and fix a list of files that were copied, using rsync, from a bad (BAD!) hard drive to another hard drive (let's call that one the savior drive).
* Since the bad drive is so bad, the data that was copied off that drive might have been corrupted.
* So we'll find which of the listed files are wrong (different MD5 checksum on both drives), and fix them.
*
* Lucky for us, the dying drive is SO BAD that it never generates the same read errors, and when it does generate errors, the byte it reads is always exactly 0x10 (decimal 16) less than it should be.
* This very particular way of dying allows us to detect which of the two drive has the correct byte, and thus write a correct file on the savior drive.
* Hooray!
@gboudreau
gboudreau / nissan-connect-encryption.html
Created March 18, 2016 13:55
Nissan Connect API encryption using Javascript
<script src="http://sladex.org/blowfish.js/ext/blowfish.js"></script>
<script>
var password = 'a';
var key = 'uyI5Dj9g8VCOFDnBRUbr3g';
var encrypted_password = blowfish.encrypt(password, key, {cipherMode: 0, outputType: 0});
console.log("Encrypted password: " + encrypted_password);
</script>
@gboudreau
gboudreau / NissanConnectEncryption.java
Created March 18, 2016 13:57
Nissan Connect API encryption using Java
package me.netlift.mobile.activities;
import android.util.Base64;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class NissanConnectEncryption {
@gboudreau
gboudreau / nissan-connect-encryption.php
Last active June 27, 2020 17:27
Nissan Connect API encryption using PHP
<?php
function encrypt($password, $key = 'uyI5Dj9g8VCOFDnBRUbr3g') {
$size = @call_user_func('mcrypt_get_block_size', MCRYPT_BLOWFISH);
if (empty($size)) {
$size = @call_user_func('mcrypt_get_block_size', MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
}
$password = pkcs5_pad($password, $size);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND);
$passcrypt = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $password, MCRYPT_MODE_ECB, $iv);
@gboudreau
gboudreau / _etc_ssh_sshd_config
Created May 11, 2016 20:10
Fix GitKraken not being able to pull/push from my gogs.io repos
# GitKraken needs diffie-hellman-group14-sha1
#KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1