Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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 / pixel_tracker.php
Created January 5, 2016 15:56
Function to track visitor information (e. g. pixel tracker)
// callback
function get_server_info($k) {
return '"' . (isset($_SERVER[$k]) ? $_SERVER[$k] : '-') . '"';
}
// format: 2016/01/06-15:38:40 10.0.0.1 "/p.gif?page=home" "Mozilla/5.0" "http://ref.co"
function track_visitor() {
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$client_ip = $_SERVER['REMOTE_ADDR'];
} else {
@cmaas
cmaas / headlines-to-permalinks.js
Last active February 2, 2016 11:57
Adds permalink anchor to all headlines in an article
@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 / phpbb-login-by-email.md
Last active June 25, 2019 08:42
PHPBB3: Login by email and authenticate at ACP

PhpBB3: Login by email and re-authenticate at ACP

I made a custom auth provider that accepts the email as username. However, if you try to login to the ACP, you get this error:

You are not able to re-authenticate as a different user.

The problem causing this is in the file includes/functions.php. When you re-authenticate for the ACP, the provided username is compared with the user data (around line 2358):

// Check if the supplied username is equal to the one stored within the database if re-authenticating