Skip to content

Instantly share code, notes, and snippets.

@badsyntax
badsyntax / gist:660417
Created November 2, 2010 22:24
a shell snippet to use google's closure compiler to minify a javascipt file
in=yourfile.js
out=yourfile.min.js
curl -s \
-d compilation_level=SIMPLE_OPTIMIZATIONS \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@${in}" \
http://closure-compiler.appspot.com/compile \
> $out
@badsyntax
badsyntax / maxlength.js
Created November 15, 2010 13:08
maxlength.js
(function($){
// a tiny jquery plugin to deal with maxlength attribute on textareas
// TODO: how do we know when the browser is capable of implementing/handling this HTML5 attribute?
// can we assume if the browser supports this attribute it will handle it correctly?
// example usage: $('textarea[maxlength]').maxlength();
$.fn.maxlength = function(){
return this.bind('keydown blur', function(){
@badsyntax
badsyntax / nofouc.html
Created November 19, 2010 14:10
Adding 'js' classname to HTML tag to prevent FOUC of Javascript components
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">document.documentElement.className += " js";</script>
<link rel="stylesheet" href="css/style.css?v=2">
</head>
<body>
#!/usr/bin/env bash
#
# build a new kohana3 project using the kohana3-examples repository
# https://github.com/badsyntax/kohana3-examples
if ! builtin type -p git > /dev/null ; then
echo git doesn\'t appear to be installed.; exit 1
fi
@badsyntax
badsyntax / openid.php
Created November 28, 2010 09:55
Example Kohana3 OpenID controller
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This is a Kohana3 ported version of the php-openid example consumer files
* see https://github.com/openid/php-openid/tree/master/examples/consumer/
* For instructions see http://blog.badsyntax.co/post/1668974231/kohana3-openid-module
*/
class Controller_Auth_OpenID extends Controller_Base {
protected $store_path = '/tmp/_php_consumer_test';
@badsyntax
badsyntax / email_validation.js
Created November 29, 2010 10:32
rfc822 email validation in JS
// See http://rosskendall.com/blog/web/javascript-function-to-check-an-email-address-conforms-to-rfc822
function isEmail(email){
return /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test( email );
}
@badsyntax
badsyntax / config.sql
Created December 5, 2010 16:00
Kohana 3 mysql config table schema
CREATE TABLE IF NOT EXISTS `config` (
`id` int(11) NOT NULL auto_increment,
`group_name` varchar(32) character set utf8 NOT NULL,
`config_key` varchar(32) character set utf8 NOT NULL,
`label` varchar(64) character set utf8 NOT NULL,
`config_value` text character set utf8,
`default` text character set utf8,
`rules` text character set utf8,
`field_type` varchar(255) character set utf8 NOT NULL default 'text',
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
@badsyntax
badsyntax / clean_email.js
Created December 13, 2010 15:52
converted HEX 'encoded' emails to plain HTML
function convert(content){
// This seems pretty reliable now
return content
.replace(/=\s*\n/g, '') // remove line endings
.replace(/=(([a-f0-9]){2})/ig, function(m, hex){ // HEX codes (format: =0A)
var charCode = parseInt(hex, 16); // Convert HEX code to CharCode
@badsyntax
badsyntax / editor_plugin.js
Created December 19, 2010 19:42
TinyMCE jQuery UI Inline Popups
/**
* @filename : editor_plugin.js
* @description : jQuery UI Inline Popups plugin to replace the default inlinepopups
* @developer : badsyntax (Richard Willis)
* @contact : http://badsyntax.co
* @moreinfo : http://is.gd/j1FuI
*/
/* NOTE: this code is out of date, please grab the latest code from https://github.com/badsyntax/tinymce-custom-inlinepopups/blob/master/jqueryinlinepopups/ */
@badsyntax
badsyntax / init.js
Created January 2, 2011 00:58
Kohana 3 Javascript MVC
// Example init
// This should go at the end of the document
(function(){
KO.init({
environment: 'development',
paths: {"base":"\/admin"},
param: {},
route: {
controller: 'home',