Skip to content

Instantly share code, notes, and snippets.

View peterdemartini's full-sized avatar
😎
being awesome

Peter DeMartini peterdemartini

😎
being awesome
View GitHub Profile
@peterdemartini
peterdemartini / DragonBallZ-Script.php
Last active December 29, 2015 11:09
Video game script, I think it's hilarious. Funny, Coding Humor. Great for testing SugarCRM or calling save() on all Contact
<?php
//Define Entry Point
if(!defined('sugarEntry'))define('sugarEntry', true);
chdir(realpath(dirname(__FILE__)));
require_once('include/entryPoint.php');
class PowerMove {
private $db;
private $hitpoints; //AKA contacts
private $wave = 0; // AKA Page
@peterdemartini
peterdemartini / 0_reuse_code.js
Created December 4, 2013 16:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@peterdemartini
peterdemartini / cpio_copy.sh
Created December 4, 2013 17:49
CPIO Copy Directory Command. Great for moving all files including hidden.
cd /path/to/original/location
find . -depth -print | cpio -pdum /path/to/new/location
@peterdemartini
peterdemartini / new_gist_file.sh
Created December 4, 2013 17:55
Collection of tar commands. Great for backing up and restoring directories.
#Tar and gzip with excludes
tar -zcvf backup.tar.gz --exclude="*.zip" --exclude="*.sql" *
#Tar and gzip while putting file in foriegn location
tar -zcvf /usr/local/backups/backup.tar.gz *
#Just tar
tar -cvf /usr/local/backups/backup.tar *
#Restore from tar.gz
cd /location/to/untar/to
tar -zxvf /path/to/backup.tar.gz
@peterdemartini
peterdemartini / findinfiles.sh
Created December 4, 2013 17:58
Best Find in Files command for Linux. Show lines number, displays results efficiently using less.
#With Extension (PHP)
find . -iname "*.php" -print0 | xargs -0 grep -i -n 'Search Term' | less
#Without Extension
find . -iname "*" -print0 | xargs -0 grep -i -n 'Search Term' | less
@peterdemartini
peterdemartini / SEF_Converter.php
Created December 11, 2013 00:37
Search Engine Friendly String converter.
<?php
function generate_seo_link($string, $replace = '-'){
$string = strtolower($string);
//remove query string
if(preg_match("#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i",$string)){
$parsed_url = parse_url($string);
$string = $parsed_url['host'].' '.$parsed_url['path'];
}
@peterdemartini
peterdemartini / sugarcrm_convert_date.php
Created December 12, 2013 21:56
SugarCRM Convert Date from DB to User Format
<?php
global $timedate;
$timedate->swap_formats(date('Y-m-d'), $timedate->dbDayFormat, $timedate->get_date_format());
@peterdemartini
peterdemartini / sugar_send_email.php
Created December 20, 2013 16:47
SugarCRM Send Email via PHP
<?php
function send_report_email($subject, $body, $emails){
require_once('include/SugarPHPMailer.php');
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
@peterdemartini
peterdemartini / sugar_script.php
Created December 20, 2013 16:54
SugarCRM entryPoint in the root of Sugar. Great for scripts.
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
chdir(realpath(dirname(__FILE__)));
require_once('include/entryPoint.php');
//Running with SugarCRM
//Custom Code Goes below here
@peterdemartini
peterdemartini / new_gist_file.php
Created March 4, 2014 18:44
SugarCRM Custom JSON API Entry Point
<?php
class CustomAPI {
var $inbound = false;
public function __construct(){
$this->inbound = $this->parse_inbound_json();
}
public function get_inbound(){ return $this->inbound; }