Skip to content

Instantly share code, notes, and snippets.

@cmaas
cmaas / backup-sd-card.txt
Created February 28, 2015 12:04
Backup of an SD Card on OS X with dd
diskutil list
diskutil unmountdisk /dev/disk2s1
dd if=/dev/disk2s1 of=card.img bs=1m
Check status of dd by pressing Ctrl + T in Terminal.
@cmaas
cmaas / laravel-type-object.md
Last active August 29, 2015 14:15
Laravel: Basic Value Object with Predefined Range of Accepted Values (Type Object)

Laravel: Basic Value Object with Predefined Range of Accepted Values

Your model has a list of accepted values. Say, your student score can be low, medium, or high. You want to store these values as Integers in the database and as a programmer, you want to work with constants like so:

Score::MEDIUM

Also, your HTML <select> field should have options for all available Constant values and label them with a translated label from your language file.

@cmaas
cmaas / laravel-value-object.md
Last active October 24, 2017 10:25
Laravel: Basic Value Object

Laravel: Basic Value Object

If you want to enforce certain values in your models, you can use simple value objects for this job. This class helps to reuse some of the logic:

/**
 * Representation of a simple value object with a single attribute that should be validated
 *
 * @package Demo
 */
@cmaas
cmaas / knockout-dirtyflag.js
Created February 10, 2015 14:42
Knockout: Dirty Flag / Dirty Tracking
// dirty tracking
// original: https://github.com/tekpub/knockout-cart/blob/master/src/cart.js
ko.computed(function(){
// do things like:
// localStorage.setItem("tekpubCart",ko.toJSON(self.items));
}).extend({throttle : 1});
@cmaas
cmaas / knockout-extensions.js
Created February 10, 2015 14:27
Knockout: Force a positive integer
// extension to replace an observable with a writeable computed that forces write to be numeric
// original: https://github.com/tekpub/knockout-cart/blob/master/src/extensions.js
ko.observable.fn.asPositiveInteger = function(defaultForBadValue) {
var original = this,
interceptor = ko.computed({
read: original,
write: function(newValue) {
var parsed = parseInt(newValue, 10);
//if value is bad or negative, then use default
if (isNaN(parsed) || parsed < 0) {
@cmaas
cmaas / laravel-update-mysql-datetime.md
Created January 29, 2015 15:24
Laravel 4 – Update MySQL DATETIME field and increase value with DATE_ADD

Update MySQL DATETIME field and increase value with DATE_ADD

You can update a MySQL DATETIME field in Laravel with Eloquent like so:

DB::table('users')
    ->where('id', $user_id)
    ->update(array('valid_until' => DB::raw('DATE_ADD(valid_until, INTERVAL 1 MONTH)')));
@cmaas
cmaas / laravel-mail-from-multiple-domains.md
Last active August 29, 2015 14:14
Laravel 4 – Mail from address with multiple domains

Send mails in Laravel 4 and configure "From" for multiple domains

In app/config/mail.php set the line with "from" to the following:

    'from' => array('address' => 'info@' . str_replace('www.', '', Request::getHost()), 'name' => 'Yourname'),

Use Request::getHost() for the whole domain (includes www if applicable). Request::getHttpHost() also includes the port number, Request::root() includes the protocol as well.

@cmaas
cmaas / piwik-tracking.js
Created October 23, 2014 15:22
A simple Piwik tracking plugin for your Impact.js games.
/**
* Loosely based on tracking.js for Google Analytics by Jesse Freeman: https://gist.github.com/jessefreeman/7531064
* How to Use:
* - Copy to your lib/plugins folder, require in main.js
*
* - in main.js init():
* this.tracking = new PiwikTracking();
* ig.game.tracking = this.tracking;
*
* - install Piwik tracking code in your index.html like you normally do