Skip to content

Instantly share code, notes, and snippets.

View greyaperez's full-sized avatar

Grey Perez greyaperez

View GitHub Profile
@greyaperez
greyaperez / composer_global_require.sh
Created January 13, 2014 02:44
Globally Install a Package
# Exec
composer global require '{APP PACKAGE}'
# Example
composer global require 'phpunit/phpunit=3.7.*'
@greyaperez
greyaperez / git_show_commit_hash.sh
Created January 17, 2014 15:10
Git - Show Current Commit Hash
git rev-parse HEAD
@greyaperez
greyaperez / PDO-Simple_Example.php
Created January 20, 2014 16:45
Quick & Dirty PDO Usage to MySQL DB
$pdo = new PDO( 'mysql:dbname={DBNAME};host=localhost', $user, $pass );
@greyaperez
greyaperez / tail_match_execute.sh
Created February 6, 2014 16:12
When Tailed Log matches a string, execute task.
tail -f logfile.log | while read LOGLINE
do
[[ "${LOGLINE}" == *"Server Started"* ]] && pkill -P $$ tail && {DO SOMETHING HERE}
done
@greyaperez
greyaperez / ngrok-tunnel.sh
Created February 19, 2014 15:43
NGROK Tunnel, useful commands to run
// Initial Setup - Get AUTH TOKEN from ngrok.com (Run this once)
ngrok -authtoken {AUTH TOKEN} 80
// Run Ngrok on a specific Subdomain (Ex: local.ngrok.com)
ngrok -subdomain=local 8080
@greyaperez
greyaperez / Get_Concrete_Type_of_Generic.java
Created February 27, 2014 03:49
Grab generic interfaces of a class by Class#getGenericInterfaces() which you then in turn check if it's a ParameterizedType and then grab the actual type arguments accordingly. .
// Interface
public interface FooBar<T> {
// ...
}
// Impl Class
public class BarFoo implements FooBar<Person> {
// ...
}
@greyaperez
greyaperez / Custom_Iterable.java
Created February 27, 2014 04:10
Implementation Example of Iterable Interface
/*
* Implement the java.lang.Iterable<E> interface
*/
public class MyCollection<E> implements Iterable<E>{
public Iterator<E> iterator() {
return new MyIterator<E>();
}
}
@greyaperez
greyaperez / stack_trace_or_gtfo.java
Created March 6, 2014 22:03
That returns an array of StackTraceElements that represent the current stack trace of a program.
// Array of StackTraceElements
Thread.currentThread().getStackTrace();
// Return as String, (Uses Apache Commons Lib)
String fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e);
// Get Defined Position of Current Method
(new Throwable()).getStackTrace();
#########################################################
# Step 1 - Create /etc/init.d/{service-name} File
#########################################################
#!/bin/sh
### BEGIN INIT INFO
# Provides: service-name
# Short-Description: Management of {Service Name}
### END INIT INFO
@greyaperez
greyaperez / Get_Relevant_StackTrace.java
Created March 13, 2014 19:13
Get nice output of the current relevant stack in your app. Insert this snippet anywhere in your code (ideally closer to the last class / method being called).
System.out.println("##################\n Relevant Stack\n##################");
for(StackTraceElement stackelement : Thread.currentThread().getStackTrace()){
String[] elementClass = stackelement.getClassName().split("\\.");
// Set Relevant Packages Here (com by default)
if( elementClass.length > 3 && elementClass[0].equals("com") ) {
System.out.println( stackelement.getClassName() + " :: " + stackelement.getMethodName() + "()");
}
}
System.out.println("##################\n [end] Relevant Stack\n##################\n\n");