Skip to content

Instantly share code, notes, and snippets.

View james2doyle's full-sized avatar

James Doyle james2doyle

View GitHub Profile
@james2doyle
james2doyle / ckeditor.toolbar.js
Created August 26, 2015 17:12
CKEDITOR Toolbar config
config.toolbar = 'Full';
config.toolbar_Full =
[
{ name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
'HiddenField' ] },
'/',
@james2doyle
james2doyle / filter.php
Last active August 29, 2015 13:56
Sanatize and filter $_GET and $_POST data that handles arrays and is recursive. http://goo.gl/Fonl6D
// Filters data against security risks.
function filter($data) {
if (is_array($data)) {
foreach ($data as $key => $element) {
$data[$key] = filter($element);
}
} else {
$data = trim(htmlentities(strip_tags($data)));
if(get_magic_quotes_gpc()) {
$data = stripslashes($data);
@james2doyle
james2doyle / upload-file.php
Last active August 29, 2015 13:56
simple file upload handler with PHP
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
function slugify($text) {
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
@james2doyle
james2doyle / image-list.php
Created February 22, 2014 16:34
list a folder of images and store the values in an array
<?php
$images = array();
if ($handle = opendir('uploads')) {
while (false !== ($entry = readdir($handle))) {
$check = preg_match("/\.(jpg|jpeg|png|gif|webp)/i", $entry);
if ($entry != "." && $entry != ".." && $check) {
$alt = preg_replace('/\.(jpg|jpeg|png|gif|webp)/', '', $entry);
$image_info = getimagesize('uploads/'.$entry);
$images[] = array(
@james2doyle
james2doyle / $.fn.swappable.js
Created February 22, 2014 22:55
a small jquery plugin that causes elements to turn it into a input fields
$.fn.extend( {
swappable: function(options) {
this.defaults = {
id: 'swappable-temp-input',
class: 'swappable-input',
name: 'swappable-temp',
type: 'input',
evt: 'click',
end: 'blur',
detectTag: true,
@james2doyle
james2doyle / replace-css-vars.d
Created March 3, 2014 02:50
A small script written in D that replaces LESS style variables in a file.
// compile with: gdmd -O -inline -release -noboundscheck replace-css-vars.d
// usage: ./replace-css-vars text.less
import std.stdio, std.file, std.regex, std.string;
string FILE;
// empty a line
string clearLine(string content, string subject) {
auto com = regex(subject, "g");
auto newcontent = replaceAll(content, com, "");
@james2doyle
james2doyle / Cronjob.txt
Created March 26, 2014 03:03
Syntax for running cron jobs
# min (0-59), hour (0-23), DOM (1-31), MOY (1-12), DOW (0-6 with 0=Sunday).
# the following will clear the Apache error log at one minute past midnight each day.
01 00 * * * echo "" > /www/apache/logs/error_log
@james2doyle
james2doyle / window.pyro.js
Created March 26, 2014 14:53
A simple header script of using in PyroCMS sites. Exposes some site data for use in javascript
window.pyro = {
base_url: "{{ url:base }}",
current_url: "{{ url:current }}",
layout: "{{ page:layout:slug }}",
segement: "{{ url:segments segment="1" }}",
module: "{{ global:module }}"
};
@james2doyle
james2doyle / string.prototype.bool.js
Created April 17, 2014 20:01
String.prototype.bool lets you check to see if a string is true or false
String.prototype.bool = function() {
return (/^true$/i).test(this);
};
@james2doyle
james2doyle / read-file-contents.applescript
Created April 30, 2014 01:45
browse for a file and read the contents into a dialog
-- only read files with MD extension
set myFile to (POSIX path of (choose file with prompt "Select a file to read:" of type {"MD"}))
-- pipe the content into cat and then apply the result to theContent
set theContent to (do shell script "cat " & myFile) of result
display dialog theContent
-- close the file
close access myFile