Skip to content

Instantly share code, notes, and snippets.

View huafu's full-sized avatar
🏠
Writing code poems from home

Huafu Gandon huafu

🏠
Writing code poems from home
View GitHub Profile
@huafu
huafu / showTest.coffee
Created February 8, 2014 17:04
Example of usit CoffeeScript abstraction library for EmberJS testing with QUnit
###*
Integration test module my composite stats show
###
class Test.MyCompositeStatsShowTest extends IntegrationTestSuite
# URL to load for ALL our tests
url: '/'
# Ajax mock groups to be used
ajaxMockGroupNames: ['basic']
@huafu
huafu / force-utc-date.coffee
Last active August 29, 2015 13:57
Forces all dates in the browser to use UTC
# force dates to be UTC
__timezoneOffset = (new Date).getTimezoneOffset() * 60 * 1000
__dateWrapper = (original) ->
->
unless @__hacked
@__hacked = yes
@setTime @getTime() - __timezoneOffset
try
res = original.apply @, arguments
catch err
@huafu
huafu / isSame.coffee
Created September 28, 2014 07:57
Deeply compare 2 variables and returns true if they are the same, else false
isSame = (obj1, obj2) ->
if obj1 is obj2
yes
else if obj1? and obj2?
if (t = typeof obj1) isnt typeof obj2
no
else
if t isnt 'object'
no
else
@huafu
huafu / with-clock.js
Last active August 29, 2015 14:07
A mixin to have a property updated each time a new `tickStep` `tickUnit` is passed
import Ember from 'ember';
var DAYS_IN_YEAR = 365.25;
var DAYS_IN_MONTH = DAYS_IN_YEAR / 12;
var MILLISECONDS_IN = {
millisecond: 1,
second: 1000,
minute: 1000 * 60,
hour: 1000 * 60 * 60,
day: 1000 * 60 * 60 * 24,
@huafu
huafu / application.js
Created October 7, 2014 10:26
Application ficture adapter with queryFixtures implementing limits, order and filters (requires momentjs)
import Ember from 'ember';
import DS from 'ember-data';
function hasOwn(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function castId(r) {
return '' + (r && r instanceof DS.Model ? r.get('id') : r);
}
@huafu
huafu / logger.coffee
Created October 21, 2014 15:46
Very simple logger to instrument objects and methods
logger =
_anonymousIndex: 0
guessMethodName: (method) ->
unless (res = (->).toString.call(method).match(/function([^\(]*)/)[1].replace(/(^\s+|\s+)$/g, ''))
res = logger.autoNamespace()
res
autoNamespace: ->
"[anonymous##{ ++logger._anonymousIndex }]"
@huafu
huafu / with-style.js
Created October 23, 2014 04:04
Add a `styleBindings` property to views which can be used like `attributeBindings`. Support units as well.
import Ember from 'ember';
/**
* @mixin WithStyleMixin
*/
var WithStyleMixin = Ember.Mixin.create({
concatenatedProperties: ['styleBindings'],
attributeBindings: ['style'],
/**
@huafu
huafu / index.html
Last active August 29, 2015 14:08
Ember Starter Kit// source http://emberjs.jsbin.com/yebaca
<script type="text/x-handlebars" data-template-name="index">
{{each itemView='dummy'}}
</script>
<script type="text/x-handlebars" data-template-name="dummy">
IN DUMMY TEMPLATE
{{view.val}} {{t}}
</script>
@huafu
huafu / search-icon.html
Created December 24, 2014 02:22
HTML search icon (magnifier)
<span style="display: inline-block;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);">
&#9906;
</span>
@huafu
huafu / app_initializers_session-service.js
Last active August 29, 2015 14:13
Basic session handling
export function initialize(container, application) {
application.inject('service:session', 'store', 'store:main');
application.inject('route', 'session', 'service:session');
application.inject('controller', 'session', 'service:session');
application.inject('model', 'session', 'service:session');
application.inject('component', 'session', 'service:session');
application.deferReadiness();
// load the current session
container.lookup('service:session').load().then(function () {
application.advanceReadiness();