Skip to content

Instantly share code, notes, and snippets.

@guiled
guiled / myClass.php
Last active March 17, 2017 10:09
Atoum How to mock a function
<?php
class myClass {
protected $creator;
public function set(callable $creator)
{
$this->creator = $creator
}
@guiled
guiled / logger.php
Last active March 13, 2017 09:41
Test write to a file
<?php
namespace Project\Log\tests\units;
use \mageekguy\atoum;
class Logger extends atoum\test
{
public function testStdout()
@guiled
guiled / test.js
Created March 26, 2015 15:26
Appcelerator iOS calendar access crash with promises
// The following code doesn't work and makes your app crashes
// Because you MUST NOT use deferred code that access to calendar
Ti.Calendar.requestEventsAuthorization(function(e) {
Ti.API.info('Authorizations success : ' + e.success);
if (e.success) {
new Promise(function (resolve) {
Ti.API.info('A');
var cal = Ti.Calendar.getDefaultCalendar();
Ti.API.info('A cal id' + cal.id);
resolve(cal);
@guiled
guiled / explode.php
Created November 25, 2014 09:04
IncredibleLines/UselessExplode
<?php
list($useless, $useless, $uesless, $code) = explode('/', $base);
@guiled
guiled / anim.js
Last active November 11, 2015 17:23 — forked from skypanther/anim.js
A fixed version for animated color in Titanium
// next two from http://stackoverflow.com/a/5624139/292947
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
global NMEs = [];
global ID = 0;
global FORCE = 1;
var enemies = getEnemies();
for (var nme in enemies) {
debug(nme + ' ' + getName(nme) + ' ' + getForce(nme));
@guiled
guiled / gist:498e1f613547266dbbce
Created June 20, 2014 15:06
Appcelerator good way to know if in portrait
// WTF On iOS for horizontal positions (iPad on a table) there are some bugs : in portrait mode e.source.isPortrait = false, Ti.Gesture.isPortrait = false and Ti.Gesture.orientation = 0 or 5 (even in portrait or landscape) !!!
// so take the old fashioned screen dimensions
Ti.Gesture.addEventListener('orientationchange', function (e) {
Alloy.Globals.isPortrait = (Ti.Platform.displayCaps.platformHeight > Ti.Platform.displayCaps.platformWidth);
});
@guiled
guiled / Application\Controller\Main.php
Created January 15, 2014 22:34
Custom Kit example in Sohoa Framework
namespace Application\Controller {
use Sohoa\Framework\Kit;
class Main extends Kit
{
public function indexAction()
{
$this->customKit->print();
<?php
namespace Application\Controller {
use Sohoa\Framework\Kit;
class Main extends Kit {
public function indexAction() {
@guiled
guiled / testWithThen.php
Created August 23, 2012 15:45
Atoum and then feature
<?php
$this->assert
->if($inc = function (&$i) { $i++; return $i})
->and($i=0)
->then('test the inc')
->number($inc($i))
->isEqualTo(1)
->then('and test it with same context')
->number($inc($i))