Skip to content

Instantly share code, notes, and snippets.

View splittingred's full-sized avatar
💭
🚀

Shaun McCormick splittingred

💭
🚀
View GitHub Profile
@splittingred
splittingred / create.class.php
Created November 1, 2011 21:26
2.2 Chunk Create Processor
<?php
require_once (dirname(dirname(__FILE__)).'/create.class.php');
/**
* Creates a chunk.
*
* @param string $name The name of the chunk.
* @param string $description (optional) The description of the chunk.
* @param integer $category The category the chunk is assigned to.
* @param string $snippet The code of the chunk.
* @param boolean $locked Whether or not the chunk can only be accessed by
<?php
require_once (dirname(dirname(__FILE__)).'/create.class.php');
/**
* Create a snippet.
*
* @param string $name The name of the element
* @param string $snippet The code of the snippet.
* @param string $description (optional) A brief description.
* @param integer $category (optional) The category to assign to. Defaults to no
* category.
@splittingred
splittingred / update.class.php
Created November 2, 2011 18:53
The nice and short Category update processor in MODX 2.2
<?php
class modElementCategoryUpdateProcessor extends modObjectUpdateProcessor {
public $classKey = 'modCategory';
public $languageTopics = array('category');
public $permission = 'save_category';
public $objectType = 'category';
}
return 'modElementCategoryUpdateProcessor';
@splittingred
splittingred / gist:1435521
Created December 5, 2011 21:46
MODX 2.2 line count report, 12/5/2011
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
PHP 2218 24654 71713 180956
Javascript 223 3906 5440 49419
CSS 99 5030 1072 24588
XML 16 469 303 2903
Java 1 47 62 182
SQL 4 20 37 120
Smarty 3 5 0 58
@splittingred
splittingred / simple-benchmark.php
Created March 9, 2012 05:37
simple-benchmark.php
<?php
set_time_limit(0);
class Timer {
public $timer = 0;
public function start() {
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$this->timer = $mtime;
@splittingred
splittingred / .htaccess
Created April 9, 2012 21:48
Example of how to use new REST server class in MODX 2.3+
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ rest/index.php?_rest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ rest/index.php [QSA,NC,L]
</IfModule>
@splittingred
splittingred / gist:2353708
Created April 10, 2012 19:03
twitter search criteria for #modx hashtag
modx -2by2host -from:modx -from:modx_feeds -to:modx -from:wehatejbieber -modx_ch -mr_modx -/logs/modx -noon_modx lang:en
@splittingred
splittingred / transport.menu.php
Created April 20, 2012 18:45 — forked from BobRay/transport.menu.php
MODX menu transport file (for MODX 2.3)
/* will route to the first found of the following:
[namespace-path]controllers/[manager-theme]/index.class.php
[namespace-path]controllers/default/index.class.php
[namespace-path]controllers/index.class.php
*/
$menu= $modx->newObject('modMenu');
$menu->fromArray(array(
'text' => 'mycomponent',
'parent' => 'components',
'description' => 'mycomponent.menu_desc',
@splittingred
splittingred / gist:4689218
Last active April 30, 2019 09:39
Example of modRest, a REST Client, in MODX 2.3.
$config = array(
'baseUrl' => rtrim('http://mywebsite.com/rest/api/','/'),
'format' => 'json', // json or xml, the format to request
'suppressSuffix' => false, // if false, will append .json or .xml to the URI requested
'username' => 'myuser', // if set, will use cURL auth to authenticate user
'password' => 'mypass',
'curlOptions' => array(
'timeout' => 30, // cURL timeout
'otherCurlOption' => 1,
@splittingred
splittingred / normalized_word_frequency.rb
Last active December 14, 2015 05:29
Finds a normalized ranking of word frequency given an article of text
##
# Finds a normalized ranking of word frequency given an article of text
#
class Hash
##
# Normalize the array to values between 0 and 1
#
# @param [Boolean] weight_lower_value Set to true to give more weight to lower values
#
def normalize(weight_lower_value = false)