Skip to content

Instantly share code, notes, and snippets.

View crisu83's full-sized avatar
🎩
Coding

Christoffer Niska crisu83

🎩
Coding
View GitHub Profile
@crisu83
crisu83 / inherit.js
Last active January 4, 2016 18:19
Simple function for extending objects in JavaScript without breaking the prototype chain (uses underscore.js and Object.create()).
/*!
Usage:
// define a base class called 'A'
// inheriting 'null' will inherit an empty constructor,
// this is convenient because you can define all your classes using the inherit method.
// protip: use upper case for classes, lower case for instances
var A = inherit(null, {
doSomething: function() {}
});
<?php
/**
* TbJqueryFileUpload class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package yiistrap-widgets.widgets
*/
/**
@crisu83
crisu83 / codrops-provider.js
Last active December 25, 2015 19:38
Codrops provider for StartHQ
[
  {
    query: 'http://tympanus.net/codrops/?s={{term}}',
    translate: 'parseHTML(response)',
    icon:{
      selector: '.ct-row > article > .ct-latest-thumb',
      expression: 'app.url|icons'
    },
    name:{
      selector: '.ct-row > article > h3 > a',
@crisu83
crisu83 / coderwall-provider.js
Created October 17, 2013 16:13
Coderwall provider for StartHQ
[
  {
    query: 'https://coderwall.com/p/search?scope=everything&search={{term}}',
    translate: 'parseHTML(response)',
    icon:{
      selector: '.avatars li:first-child a',
      expression: 'app.url|icons'
    },
    name:{
      selector: '.protip a.title',
@crisu83
crisu83 / JsonAttributeBehavior.php
Created October 11, 2013 08:01
Active record behavior for handling JSON attributes.
<?php
/**
* Active record behavior for handling JSON attributes.
*
* @property CActiveRecord $owner
*/
class JsonAttributeBehavior extends CActiveRecordBehavior
{
/**
@crisu83
crisu83 / jsWarriorLogic
Last active December 25, 2015 05:49
Logic for jsWarrior to beat the game. http://jswarrior.fusioncharts.com/
var maxHealth = 20,
criticalHealth = 5,
checkedBehind = false;
jsWarrior.turn = function(warrior) {
warrior.takingDamage = warrior.lastHealth > warrior.getHealth();
if (warrior.check() == "enemy") {
warrior.attack();
}
/**
* Initializes the application.
*/
var initialize = function() {
var self = this;
$('*[data-view]').each(function() {
var $el = $(this),
viewClass = 'app/views/' + $el.data('view');
require([viewClass], function(View) {
new View({el: $el[0], app: self});
<?php
class I18nAttributeBehavior extends CActiveRecordBehavior
{
/**
* @var array a list of translatable attributes.
*/
public $attributes = array();
/**
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# VMWare
config.vm.box = "precise64_vmware"
config.vm.box_url = "http://files.vagrantup.com/precise64_vmware.box";
config.vm.network :public_network
<?php
/**
* Returns the active language.
* @return string the locale.
*/
public function resolveActiveLanguage()
{
$user = user();
$matches = array();
if ($user->hasState('__locale')) {