Skip to content

Instantly share code, notes, and snippets.

@thsur
thsur / bitwise.php
Created March 22, 2021 13:54 — forked from ryanwinchester/bitwise.php
BITWISE FLAGS for Custom PHP Objects
<?php
/**
* BITWISE FLAGS for Custom PHP Objects
*
* @link http://php.net/manual/en/language.operators.bitwise.php#108679
*
* Sometimes I need a custom PHP Object that holds several boolean TRUE or FALSE values.
* I could easily include a variable for each of them, but as always, code has a way to
* get unweildy pretty fast. A more intelligent approach always seems to be the answer,
@thsur
thsur / HEY-YOU.md
Created June 1, 2017 09:30 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@thsur
thsur / init_gitflow.rake
Created March 1, 2017 16:46 — forked from fnichol/init_gitflow.rake
Register rake tasks off `rake init' to setup your initial development environment after a fresh git clone. N.B. better to make these actions idempotent so you can run it more than once without fear.
namespace :init do
task 'gitflow_init' do
preconditions = [
%{git config --get gitflow.branch.master >/dev/null 2>&1},
%{git config --get gitflow.branch.develop >/dev/null 2>&1},
%{git config --get gitflow.prefix.feature >/dev/null 2>&1},
%{git config --get gitflow.prefix.release >/dev/null 2>&1},
%{git config --get gitflow.prefix.hotfix >/dev/null 2>&1},
%{git config --get gitflow.prefix.support >/dev/null 2>&1},
%{git config --get gitflow.prefix.versiontag >/dev/null 2>&1}
@thsur
thsur / configure.rb
Created March 29, 2016 20:08 — forked from tansengming/configure.rb
Ruby configure blocks
# How Clearance / Hoptoad does it
module Clearance
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
@thsur
thsur / wpalchemy.patch
Last active August 29, 2015 14:03
WPAlchemy Output Filter Patch
diff --git a/content/themes/roots/lib/vendor/wpalchemy/MetaBox.php b/content/themes/roots/lib/vendor/wpalchemy/MetaBox.php
index 7309489..d081801 100644
--- a/content/themes/roots/lib/vendor/wpalchemy/MetaBox.php
+++ b/content/themes/roots/lib/vendor/wpalchemy/MetaBox.php
@@ -1331,7 +1331,7 @@ class WPAlchemy_MetaBox
// filter: output (can_output)
if ($this->has_filter('output'))
{
- $can_output = $this->apply_filters('output', $post_id);
+ $can_output = $this->apply_filters('output', array($post_id, $can_output, $this));
@thsur
thsur / convert_storage_mode.php
Last active August 29, 2015 14:02
WordPress - Convert storage mode of post meta data
if ( ! function_exists( 'convert_meta_storage' ) ) :
function convert_meta_storage($key, $prefix, $posttype) {
$args = array(
'numberposts' => -1,
'post_type' => $posttype,
);
$items = get_posts($args);
@thsur
thsur / usage.js
Last active August 29, 2015 14:02
WordPress Custom Media Uploader
jQuery(document).ready(function($){
// Configure
var config = {
// Overwrite default settings
wpmedia: {
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
<?php
// client side: assume user has maliciously used the following values in a form search input field and submitted
$field = '<input type="text" name="query" value="%slow_your_db" />';
// server-side: assume retrieval of form search input value
$search_term = !empty($_GET['query']) ? $_GET['query'] : NULL;
// try to escape the input before querying, but we fail to escape the qualifier
// and it remains "%slow_your_db"
$search_term = mysql_real_escape_string($search_term);