Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ain's full-sized avatar

Ain Tohvri ain

View GitHub Profile
@ain
ain / cssmin-font-family-regex.js
Created February 3, 2014 19:47
Regex for matching the font name within minified CSS class definition.
/(\}\.form-group>\.form-control\{)(.[^}]+)(?:font-family:([^,;}]+))/i
@ain
ain / seed_migrate.patch.rake
Created November 10, 2014 17:20
Rake task to patch seed_migrate table reset failure on db:reset
# Call with rake app:db:reset
namespace :app do
namespace :db do
# Patches seed_migration issue #22
desc "Reset database incl. seeding migration"
task :reset => :environment do
puts "Resetting database..."
begin
@ain
ain / NORMSINV.mxml
Created March 21, 2011 13:48
Returns the inverse of the standard normal cumulative distribution.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function inverseCumulativeNormalDistribution(v:Number):Number{
//refer http://home.online.no/~pjacklam/notes/invnorm/ for how this works
@ain
ain / PPPlane.as
Created February 23, 2012 20:13
AS3 visible bounds of DisplayObject
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.Rectangle;
import flash.geom.PerspectiveProjection;
import flash.display.BitmapData;
public class PPPlane extends Sprite {
@ain
ain / str_replace.as
Created February 23, 2012 19:55
String.replace() method for ActionScript2
String.prototype.replace = function(searchStr, replaceStr):String {
return this.split(searchStr).join(replaceStr);
};
@ain
ain / config.inc.php
Created July 14, 2012 16:50
phpMyAdmin configuration for local development sandbox on Mac OS X
<?php
/**
* phpMyAdmin configuration
*
* For local development sandbox on Mac OS X
* with Mac-bundled PHP and Apache instances
*
* phpMyAdmin 3.5.2
*/
@ain
ain / SafeDoctrineMigrationBase
Created November 7, 2012 22:34
Symfony 1.4 Doctrine migration base class for checking against existance of the table/field
<?php
abstract class SafeDoctrineMigrationBase extends Doctrine_Migration_Base
{
public function hasField($table, $field)
{
$conn = Doctrine_Manager::connection();
$result = $conn->execute("SHOW COLUMNS FROM $table LIKE '$field'");
$fields = $result->fetchAll();
return !empty($fields);
@ain
ain / sfWidgetFormSelectRadioSingleable.class.php
Created November 28, 2012 22:13
sfWidgetFormSelectRadioSingleable Symfony widget lets you render just one option at a time. Extends sfWidgetFormSelectRadio.
<?php
class sfWidgetFormSelectRadioSingleable extends sfWidgetFormSelectRadio
{
public function formatChoices($name, $value, $choices, $attributes)
{
$onlyChoice = !empty($attributes['only_choice']) ? $attributes['only_choice'] : false;
unset($attributes['only_choice']);
if ($onlyChoice)
@ain
ain / MyBaseForm.class.php
Created December 9, 2012 15:15
Symfony 1.4 base form class with a method to output all errors of a Form in one array
<?php
class MyBaseForm extends sfFormSymfony
{
public function getErrors()
{
$errors = array();
foreach ($this as $form_field)
{
<?php
/**
* Displays the current migration version of the database
*
* @version 1.0
* @author Ain Tohvri <at@interactive-pioneers.de>
* @see sfBaseTask
*/
class currentMigrationVersionTask extends sfBaseTask