Skip to content

Instantly share code, notes, and snippets.

View greyaperez's full-sized avatar

Grey Perez greyaperez

View GitHub Profile
#!/bin/sh
# ALIASES
alias editbash='vim ~/.bashrc'
alias updatebash='source ~/.bashrc'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias shutdown='shutdown -P now'
@greyaperez
greyaperez / quick_and_dirty_login.php
Created March 21, 2014 14:16
Very quick and dirty login, just add this entire script above the stuff in your index.php file.
<?php
// SET YOUR USER/PASS STUFF HERE...
$auth = array(
'user1' => 'pass123',
'user2' => 'pass123',
'user3' => 'pass123',
'user4' => 'pass123',
'user5' => 'pass123',
);
@greyaperez
greyaperez / apt-get-common.sh
Created March 17, 2014 04:02
Common & Useful apt-get/apt-cache commands
# Install Something (duh...)
apt-get install {package name}
# Search for Package in Repos
apt-cache search
# Get Package Info In Detail (including version)
apt-cache show {package name}
# Remove a Package
@greyaperez
greyaperez / install_npm_module_globally.sh
Created March 16, 2014 22:04
Install NPM Module Globally... avoid headache
# Install NPM Module Globally
sudo npm install -g {module name}
# example
sudo npm install -g connect
@greyaperez
greyaperez / path_of_app_binary.sh
Created March 16, 2014 21:44
Find where the bin of an app is located
# Shows you where the app is coming from
which {app}
# Example...
which java
# returns: /usr/bin/java
@greyaperez
greyaperez / isBusinessDay.java
Last active April 21, 2023 08:42
Function to Check Whether Date is a Business Day or Not (ex: Weekend or Holiday)
/**
* Is Date A Business Day?
* @param cal
* @return boolean
*/
public boolean isBusinessDay(Calendar cal){
// check if weekend
if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
return false;
}
@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");
#########################################################
# 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 / 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();
@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>();
}
}