Skip to content

Instantly share code, notes, and snippets.

@cakyus
cakyus / gist:3899122
Created October 16, 2012 12:59
Example of Static Variable
class classA {
function functionA() {
static $variableA;
if (is_null($variableA)) {
$variableA = 0;
} else {
$variableA++;
}
return $variableA;
}
@cakyus
cakyus / gist:3899126
Created October 16, 2012 13:00
Example of Singleton Pattern
class classB {
private static $instance;
private $count = 0;
private function __construct() {}
static function functionB() {
if (!isset(self::$instance)) {
$className = __CLASS__;
self::$instance = new $className;
}
return self::$instance;
@cakyus
cakyus / .gitignore
Last active December 20, 2015 14:19
Bash Scripts Collection
make*
@cakyus
cakyus / git-alias.txt
Created March 23, 2014 13:37
git alias
alias.c=commit -m
alias.b=branch -v
alias.r=remote -v
alias.s=status -s
alias.a=add -A
alias.ba=branch --verbose --all
alias.la=log --graph --pretty=format:"%Cred%h%Creset%C(yellow)%d%Creset %s - %aE %Cgreen%cr%Creset" --abbrev-commit
alias.l=log -n10 --graph --pretty=format:"%Cred%h%Creset%C(yellow)%d%Creset %s - %Cblue%aE%Creset %Cgreen%cr%Creset" --abbrev-commit
alias.xa=stash apply
alias.l1=log -n 1

Oops! I accidentally deleted a local git branch, and I haven't pushed it to a remote server yet. The branch has several important commits, and it hasn't been merged with any other branches yet. How do I find the missing branch?

1. Create a list of all dangling or unreachable commits.

$ git fsck --full --no-reflogs --unreachable --lost-found
unreachable tree 4a407b1b09e0d8a16be70aa1547332432a698e18
unreachable tree 5040d8cf08c78119e66b9a3f8c4b61a240229259
unreachable tree 60c0ce61b040f5e604850f747f525e88043dae12
unreachable tree f080522d06b9853a2f18eeeb898724da4af7aed9
@cakyus
cakyus / fsx.sh
Last active August 29, 2015 14:05
md5sum based file repository
#!/bin/sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@cakyus
cakyus / x-mount.sh
Last active August 29, 2015 14:05
Auto-mount unmounted devices
#!/bin/sh
for DEVICE_PATH in `ls -1 /dev/sd*[1,2,3,4,5,6,7,8,9]`
do
DEVICE_IS_MOUNTED=`mount | grep $DEVICE_PATH | wc -l`
if [ $DEVICE_IS_MOUNTED = 1 ]
then
# skip mounted device
continue
fi
@cakyus
cakyus / watch-dmesg.bash
Created September 25, 2018 07:30
Add timestamp to the begining of dmesg output
#!/bin/bash
#
# watch-dmesg.bash
#
# Add timestamp to the begining of dmesg output
# This is only usefull when dmesg does not support "-T" parameter
#
# Crontab Entry
# * * * * * /bin/bash /home/centos/bin/watch-dmesg.bash
@cakyus
cakyus / functions.php
Last active June 10, 2019 09:13
PHP Command Line Helper
<?php
/**
* PHP Command Line Helper
*
* Source Code
*
* https://gist.github.com/cakyus/fa8871c41e8bbe0037c107d891891cad
*
* Installation
@cakyus
cakyus / main.bash
Last active July 23, 2020 11:19
Bash Command Line
#!/bin/bash
if [ -z "$DEBUG" ]; then
DEBUG=0
fi
LOG_FILE=$( dirname $0 )/$( basename $0 .bash ).$( date +'%Y%m%d' ).log
logger_debug(){
if [ $DEBUG -eq 1 ]; then