Skip to content

Instantly share code, notes, and snippets.

@huyby
huyby / remove-svn-folders
Created November 20, 2013 13:26
Recursively remove .svn folders
$ find . -name ".svn" -exec rm -rf {} \;
OR
$ find . -name ".svn" -delete
@huyby
huyby / zf-strip-require_once.md
Created November 20, 2013 13:29
Comment out 'require_once' in Zend Framwork

OSX

$ find . -name '.php' -not -wholename '/Loader/Autoloader.php' -not -wholename '*/Application.php' -print0 | xargs -0 sed -i -E 's/(require_once)/// \1/g'

@huyby
huyby / parsing-apache-logs.md
Created November 20, 2013 13:34
Examples of parsing Apache logs

Get list of referrers in an apache access log (combined) for a specific request

sudo grep "something" * | awk '{print $11}' | grep -o "http://[^\"/]*" | sort | uniq

@huyby
huyby / replace-ssh-key.md
Last active November 28, 2016 16:29
Replace or delete ssh key in authorized_key files

Test for replacement

sed -n 's#ssh-rsa.*OLD_KEY_ID#NEW_KEY# p' .ssh/authorized_keys

Test for deleting

sed -n '#ssh-rsa.*KEY_ID# p' .ssh/authorized_keys

Do replacement in multiple authorized_key files (change maxdepth to your needs)

@huyby
huyby / ffmpeg-web-video.md
Last active August 30, 2016 14:24
Use ffmpeg/ffmpeg2theora to convert video to formats suitable for web usage, convertors like Miro Video Converter don't always have good results. Also check ffmpegx GUI.
@huyby
huyby / php_cli_xdebug.md
Created November 26, 2013 08:49
PHP cli debugging with Netbeans

PHP cli config

Check cli config if xdebug is configured.

Xdebug ide key

Export 'XDEBUG_CONFIG' with 'idekey=netbeans-xdebug'

$ export XDEBUG_CONFIG="idekey=netbeans-xdebug"

@huyby
huyby / createmysqldb.sh
Last active August 29, 2015 14:23
Create a MySQL database, dito user and random generated password.
#!/bin/sh
# Tiny script to create a mysql user and database with same
# name. A random password is generated (yay!)
usage() {
cat << __EOT
Usage: createmysqldb.sh <dbname>
where <dbname> is the one-word name you'd like to use as database name and
username if -u parameter is not set.
Options:
@huyby
huyby / laravel.sh
Last active December 15, 2015 14:54
Bash script for a quick(er) Laravel applicaton setup
#!/usr/bin/env bash
# Prompt for Yes/No answer
# $1 - question
# $2 - default answer (Y|N)
ask() {
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@huyby
huyby / ssh_port_forwarding
Created March 6, 2017 13:46
SSH port forwarding commands; useful for forwarding a remote database connection over SSH in combination with other configurations like a jump host (bastion)
# Overview on SSH port forwarding: http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html
# Example of MySQL database connection tunnel using a jump host
ssh -F ./ssh.cfg -nNT -L 33060:localhost:3306 remotehost
# ./.ssh.cfg contents
Host bastion
Hostname 8.8.8.8
User bastion-user
--- ./src/Controller/FieldablePathController.php 2017-05-18 11:51:40.000000000 +0200
+++ ./src/Controller/FieldablePathController.php 2017-05-18 11:59:01.000000000 +0200
@@ -43,7 +43,7 @@
->load($params[$entity_type]);
// Make sure the current entity exists and contains path field.
- if (empty($entity) || !$entity->hasField('path')) {
+ if (empty($entity) || !(method_exists($entity, 'hasField') && $entity->hasField('path'))) {
return;
}