Skip to content

Instantly share code, notes, and snippets.

View FMCorz's full-sized avatar

Frédéric Massart FMCorz

  • Branch Up Pty Ltd
  • Perth, Australia
View GitHub Profile
@FMCorz
FMCorz / cli.md
Created July 11, 2016 03:13
Find and replace in files

Find all the .php files in the current directory and below, and replace FROM with TO.

find . -type f -iname '*.php' -exec sed -i 's/FROM/TO/g' {}  \;
@FMCorz
FMCorz / ssh_port_forward.md
Last active January 9, 2023 21:41
Port forwarding using SSH

Local port forwarding

ssh -nNT -L LOCALPORT:DESTINATION:DESTPORT SSHACCOUNT

To forward localhost:5000 to destination.net:80:

@FMCorz
FMCorz / gitconfig
Last active November 23, 2022 12:26
Global git config
# Edit using:
# git config -e --global
[user]
name = Me
email = email@example.com
[alias]
ap = add -p
au = add -u
bl = branch -l
@FMCorz
FMCorz / kodi.sql
Last active March 23, 2018 21:20
Find duplicate movies in Kodi
-- Find the file ~/.kodi/userdata/MyVideosXX.db
-- Open with sqlite3
-- Run the following statement:
SELECT
m.c00, -- Movie name
p.strPath, -- Path
f.strFilename -- File name
FROM movie m
@FMCorz
FMCorz / count_code.sh
Last active March 2, 2017 11:29
One liner to count lines excluding comments and empty lines
# All files, with grep
find . -type f -exec cat {} \; | grep -v -E '^\s*(//|\*|\*/|/\*\*|$)' | wc -l
# PHP Files, with awk.
find . -iname '*.php' -type f -exec cat {} \; | awk '$0 !~ /^\s*(\/\/|\*|\*\/|\/\*\*|$)/{ print $0 }' | wc -l
@FMCorz
FMCorz / merge.php
Last active May 27, 2016 20:10
PHP array merging
<?php
// Non-associative.
$a = [1, 2, 3];
$b = [4, 5, 6, 7];
$c = $a + $b;
var_dump($c);
$d = array_merge($a, $b);
@FMCorz
FMCorz / st
Created May 26, 2016 02:41
Open a file with Sublime Text
#!/bin/sh
# Place this in /usr/local/bin
# Run: chmod +x /usr/local/bin/st
exec /opt/sublime_text/sublime_text "$@"
@FMCorz
FMCorz / phpx
Created May 25, 2016 04:16
Output result of a PHP expression
#!/bin/sh
# Place in /usr/local/bin
# Run: chmod +x /usr/loca/bin/phpx
echo "<?php var_dump($@);" > /tmp/phpx.php
php /tmp/phpx.php
@FMCorz
FMCorz / application-vnd-moodle-backup.xml
Created May 25, 2016 03:43
Open MBZ files as .tar.gz files
# Add this file to ~/.local/share/mime/packages
# Run: update-mime-database ~/.local/share/mime
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-compressed-tar">
<glob pattern="*.mbz"/>
</mime-type>
</mime-info>
@FMCorz
FMCorz / prepare-commit-msg
Last active June 30, 2016 17:00
Prepare commit message hook for Moodle
# Add this to .git/hooks/prepare-commit-msg
# Then chmod +x .git/hooks/prepare-commit-msg
#
# /!\ Note, it is assumed that you have the alias `git cb`
# which returns the current branch.
if [ -z "$2" ]; then
branch=`git cb`
mdl=`expr match "$branch" 'MDL-\([0-9]\+\)-.*'`
if [ -n "$mdl" ]; then