Skip to content

Instantly share code, notes, and snippets.

@kayue
kayue / gist:625994
Created October 14, 2010 10:30
Script for a clickale button in AS3
/**
* Script for a clickale button in AS3
*/
var paramList:Object = this.root.loaderInfo.parameters;
// FYI, buttonClip is a symbol
buttonClip.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void {
<?
/**
* Give name to preg_match
*/
$haystack = '01 Jan 1970';
$pattern = '/(?<day>\d{1,2})\ (?<month>Jan|Feb)\ (?<year>19\d\d)/';
preg_match($pattern, $haystack, $matches);
print_r($matches);
#!/bin/sh
cd /home/dstrt/www
unset GIT_DIR
git pull origin master
@kayue
kayue / get_the_relative_time.php
Created January 10, 2011 04:13
Get relative time in WordPress
<?php
// This function will return "now", "3 seconds ago", "1 month ago" etc ...
function get_the_relative_time($time = null)
{
if(is_null($time)) $time = get_the_time("U");
$time_diff = date("U") - $time; // difference in second
$second = 1;
$minute = 60;
@kayue
kayue / get_trimmed_excerpt.php
Created January 10, 2011 04:18
Get trimmed excerpt (by word) in WordPress
<?php
function get_trimmed_excerpt($maxChars = 160, $appendingString = '...', $default_excerpt = "Default page description.")
{
if( !is_single() && !is_page() )
return $default_excerpt;
the_post();
$content = substr(get_the_excerpt(), 0, $maxChars);
$content = strip_tags($content);
@kayue
kayue / add_body_class.php
Created January 10, 2011 04:30
Add categories to body class in WordPress
<?php
function _add_body_class($classes, $custom_classes = false)
{
the_post();
// insert buddypress class on buddypress page
if ( function_exists("bp_is_blog_page") && !bp_is_blog_page() )
$classes[] = 'buddypress';
// add category
@kayue
kayue / bootstrapping.js
Created April 12, 2011 18:51
Javascript bootstrapping
/**
* Namespacing
* All method start with "init" will be automatically called at start.
*/
var popbee = {}
popbee.body = $("body");
popbee.initHomepage = function() {
if(!popbee.body.hasClass("homepage") return; // return if not at homepage
@kayue
kayue / gist:1086418
Created July 16, 2011 14:55
Auto pull after git push
#!/bin/sh
user='dev101'
site='hypebeast'
cd /home/$user/public_html/$site
sudo -H -u $user git pull origin v9
@kayue
kayue / index.php
Created August 25, 2011 07:05
Integrate Symfony 2 with Wordpress
<?php
require_once __DIR__.'/../symfony/app/bootstrap.php.cache';
require_once __DIR__.'/../symfony/app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$response = $kernel->handle(Request::createFromGlobals());
@kayue
kayue / RoutePatternGenerationStrategy.php
Created May 21, 2013 14:23
Hacking JMSI18nRoutingBundle, allow localization in path.
<?php
namespace Hypebeast\DesktopBundle\Router;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Routing\Route;
use JMS\I18nRoutingBundle\Router\PatternGenerationStrategyInterface;
use JMS\I18nRoutingBundle\Router\DefaultPatternGenerationStrategy;