Skip to content

Instantly share code, notes, and snippets.

View ain's full-sized avatar

Ain Tohvri ain

View GitHub Profile
@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 / log.php
Created February 23, 2012 19:47
tail functionality in PHP
<?php
// full path to text file
define("TEXT_FILE", "/home/www/default-error.log");
// number of lines to read from the end of file
define("LINES_COUNT", 10);
function read_file($file, $lines) {
//global $fsize;
@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 / 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 / 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)
{
@ain
ain / free-memory.rb
Last active December 19, 2020 22:20 — forked from vigo/free-memory.rb
#!/usr/bin/env ruby
# encoding: utf-8
# By Uğur Özyılmazel, @vigobronx | @ugurozyilmazel
# http://vigodome.com | http://ugur.ozyilmazel.com | http://github.com/vigo
def get_paged_memory_usage(match_string, paging=4096)
mvar = 3
if match_string.split(/[^\w]/).length > 1
mvar = 4
<?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