Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
hugowetterberg / ical-RFC-2445-4.1.php
Last active March 6, 2024 18:28
A useful function for splitting ical content into 75-octet lines, taking multibyte characters into account. See: http://www.ietf.org/rfc/rfc2445.txt, section 4.1
<?php
mb_internal_encoding("UTF-8");
$desc = <<<TEXT
<p>Lines of text SHOULD NOT be longer than 75 octets, (och hör på den) excluding the line break. Long content lines SHOULD be split into a multiple line representations using a line "folding" technique.</p>
That is, a long line can be split between any two characters by inserting a CRLF
immediately followed by a single linear white space character (i.e.,
SPACE, <b>US-ASCII</b> decimal 32 or HTAB, US-ASCII decimal 9). Any sequence
of CRLF followed immediately by a single linear white space character
is ignored (i.e., removed) when processing the content type.
@guybrush
guybrush / performance-parser.js
Created January 30, 2011 04:53
testing performance of parsing xml/html with nodejs
//
// this is about parsing-performance of xml/html-parsers
// to be more precisely, i just want to look for specific nodes/attributes
//
// i am testing
//
// * (htmlparser)[https://github.com/tautologistics/node-htmlparser]
// * (html5)[https://github.com/aredridel/html5]
// * (sax)[https://github.com/isaacs/sax-js]
// * (jsdom)[https://github.com/tmpvar/jsdom] + sizzle/jquery
@bpainter
bpainter / arrows.scss
Created July 15, 2011 19:08
Sass mixin for arrows based on The Shapes of CSS from Chris Coyier http://css-tricks.com/examples/ShapesOfCSS/
// --------------------------------------------------------
// arrows
// --------------------------------------------------------
// $direction: top, left, right, bottom, top-left, top-right, bottom-left, bottom-right
// $color: hex, rgb or rbga
// $size: px or em
// @example
// .element{
// @include arrow(top, #000, 50px);
// }
@rtekie
rtekie / database_semaphore.rb
Created October 18, 2011 13:04
Database semaphore mechanism used for example to guarantee that only one instance of a job will run
# Please refer to http://ctoinsights.wordpress.com/2011/10/17/running-distributed-cron-jobs-in-the-cloud/
class DatabaseSemaphore < ActiveRecord::Base
validates_presence_of :name, :message => "can't be blank"
def self.open?(name, lock_duration = 600)
# only one requestor can get open semaphore at a time
# sempahore can be locked in a closed position for lock_duration in seconds
semaphore_open = false
now = Time.now
# insert record if it does not exist yet
@chrisguitarguy
chrisguitarguy / menu-order.php
Created October 20, 2011 15:57
Add menu order to WordPress posts
<?php
/*
Plugin Name: Add Menu Order to Posts
Plugin URI: http://pmg.co/category/wordpress
Description: Adds menu order and template to post types.
Version: n/a
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
*/
@mmriis
mmriis / auth.pl
Created November 30, 2011 11:31
IMAP/POP3 proxy authentication script for nginx. See http://www.whatastruggle.com/nginx-as-an-imappop3-proxy-part-2.
#!/usr/bin/perl
use Digest::HMAC_MD5 qw/ hmac_md5_hex /;
use DBI;
use URI::Escape;
use CGI;
print "Content-type: text/html\n";
my $q = CGI->new;
@deadlyhifi
deadlyhifi / dhf_sort.css
Created December 21, 2011 17:42
WordPress - class to make custom posttypes sortable with AJAX in admin.
#sortable-list{margin-top:20px;}
#sortable-list li{padding:10px;width:50%;font-weight:bold;cursor:move;border:1px solid #ddd;background:#f5f5f5;background:-webkit-gradient(linear, left bottom, left top, color-stop(0, #eeeeee), color-stop(1, #ffffff));background:-ms-linear-gradient(bottom, #eeeeee, #ffffff);background:-moz-linear-gradient(center bottom, #eeeeee 0%, #ffffff 100%);-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-moz-background-clip:padding;-webkit-background-clip:padding-box;background-clip:padding-box;}
#loading-animation{display:none;}
@philipdowner
philipdowner / gist:1535047
Created December 29, 2011 17:16
Hidden text with background image
<style type="text/css">
body.about h1 { /*Let's presume your banner title is an h1 element */
width: 150px; /* Set this to the width of your image */
height: 75px; /* Set this to the height of your image */
background: transparent url('my-image.png') no-repeat top left; /* Change the URL to point to your image */
text-indent: -9999em; /* This ensures that the text itself will not show. */
}
</style>
<html>
@mikejolley
mikejolley / gist:1597957
Created January 12, 2012 01:40
WooCommerce - Replace '' with 'Call for price' when price is left blank
/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
return 'Call for price';
}
@mikejolley
mikejolley / gist:1604009
Created January 13, 2012 00:31
WooCommerce - Add a special field to the checkout, order emails and user/order meta
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
/**