Skip to content

Instantly share code, notes, and snippets.

View mariuswilms's full-sized avatar

Marius Wilms mariuswilms

View GitHub Profile
/**
* Date.parse with progressive enhancement for ISO-8601
* © 2010 Colin Snover <http://zetafleet.com>
* Released under MIT license.
*/
(function () {
'use strict';
var origParse = Date.parse;
Date.parse = function (date) {
var timestamp = origParse(date), minutesOffset = 0, struct;
@mariuswilms
mariuswilms / ievm_install.sh
Created November 30, 2009 22:04
Script to help with installing and converting MSs IE virtual machines for VirtualBox.
#!/bin/bash -x
#
# http://blog.mozmonkey.com/2008/vpc-ie6-ie7-ie8-on-mac-os-x/
# Requires: Q, VirtualBox
VERSION="$1"
IE_DOWNLOAD="http://download.microsoft.com/download/B/7/2/B72085AE-0F04-4C6F-9182-BF1EE90F5273/IE${VERSION}-XPSP3.exe"
WORK_DIR="/tmp/ievm"
mkdir $WORK_DIR
<?php
function transferTo($via, $from) {
extract($from);
$path = Media::short($file, $mimeType) . DS;
if (is_file($file)) {
$checksum = hash_file('adler32', $file);
} elseif (is_file($via['file'])) {
$checksum = hash_file('adler32', $via['file']);
} else {
<?php
class MoviesController extends AppController {
function edit($id = null) {
/* For a single upload */
$this->data = array(
'Movie' => array(
'file' => 'transferable item here'
));
$this->Movie->save($this->data);
<?php
class Attachment extends AppModel {
// ...
function beforeMake($file, $process = array()) {
extract($process);
if ($this->alias == 'Avatar' && $version != 's') {
return true;
}
<?php
class Movie extends AppModel {
// ...
var $hasOne = array(
'Attachment' => array(
'className' => 'Media.Attachment',
'foreignKey' => 'foreign_key',
'conditions' => array('Attachment.model' => 'Movie'),
'dependent' => true,
));
<?php
// app/controllers/movies_controller.php
class MoviesController extends AppController {
function edit($id = null) {
// ...
// $this->data = array(
// 'Movie' => array('title' => 'Vicky Cristina Barcelona'),
// 'Attachment' => array(
// 0 => array('file' => transferable item1, 'model' => 'Movie'),
// 1 => array('file' => transferable item2, 'model' => 'Movie'),
<?php
// app/models/example.php
class Example extends AppModel {
var $actsAs = array('Media.Transfer');
}
// For single uploads
// app/controllers/examples_controller.php
class ExamplesController extends AppController {
function edit($id = null) {
<?php
class Example extends MediaAppModel
// ...
var $validate = array(
// ...
'extension' => array('rule' => array('checkExtension', // order: deny, allow
array('bin', 'class', 'dll', 'dms', 'exe'), // blacklist
array('jpg', 'tmp') // whitelist
),
),
#!/bin/bash
CAKE_CORE_INCLUDE_PATH=/usr/local/share/cake-1.2.x.x
CAKE_CONSOLE=${CAKE_CORE_INCLUDE_PATH}/cake/console/cake
APP="/path/to/your/app"
MODELS="example attachments" # Models separated by one space
AUTO="-auto" # Enables automatic (destructive) repair!
if [ ! -x $CAKE_CONSOLE ] || [ ! -x $APP ]; then
exit 1