Skip to content

Instantly share code, notes, and snippets.

@eibrahim
eibrahim / arraytransform.js
Created September 17, 2014 12:14
ArrayTransform EMber
App.ArrayTransform = DS.Transform.extend({
serialize: function(jsonData) {
if (Em.typeOf(jsonData) === 'array') {
return jsonData;
} else {
return [];
}
},
deserialize: function(externalData) {
switch (Em.typeOf(externalData)) {
@eibrahim
eibrahim / gist:4162985
Created November 28, 2012 18:13
Subscribe to Mailchimp fro Azure Mobile Service
var execute = function (method, availableParams, givenParams, callback) {
var request = require('request');
var finalParams = { apikey: 'XXXXXXXX' };
var currentParam;
for (var i = 0; i < availableParams.length; i++) {
currentParam = availableParams[i];
if (typeof givenParams[currentParam] !== 'undefined')
finalParams[currentParam] = givenParams[currentParam];
}
@eibrahim
eibrahim / app.js.coffee
Created April 23, 2013 20:50
Angular safeApply helper
$rootScope.safeApply = (fn) ->
phase = $rootScope.$$phase
if phase is "$apply" or phase is "$digest"
fn() if fn and (typeof (fn) is "function")
else
@$apply fn
'use strict';
angular.module('frontendApp')
.directive('confirmButton', function (Data) {
return {
restrict: "E",
replace: true,
template: "<a id=\"{{my_id}}\" class=\"btn btn-danger confirmation-popover-button\" ng-click=\"show()\" >\n <i class=\"halflings-icon {{icon || 'trash'}}\"></i>\n</a>",
scope: {
confirm: '&',
@eibrahim
eibrahim / chosen.js
Created June 6, 2013 18:51
Angular Directive for jQuery Chosen plugin. Usage: <select chosen=""></select>
'use strict';
angular.module('frontendApp')
.directive('chosen', function ($timeout) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
var deferChosen = function(){
element.chosen({
angular.element(document).ready(function() {
var initPromise = Kinvey.init({
appKey : 'XXX-M',
appSecret : 'XXX'
});
initPromise.then(function(activeUser) {
//save user in global variable
window.activeUser = activeUser;
//load my app
@eibrahim
eibrahim / examples.exs
Created February 2, 2016 14:01
Fizzbuzz with conditional logic
def fizzbuzz n do
_fizzbuzz 1..n
end
defp _fizzbuzz a..n do
cond do
(rem(a,3) == 0 and rem(a,5) == 0) ->
IO.puts "fizzbuzz"
(rem(a,3) == 0) ->
IO.puts "fizz"
@eibrahim
eibrahim / examples.exs
Created February 2, 2016 14:02
Fizzbuzz without conditional logic
def fizzbuzzNoCond n do
_fizzbuzzNoCondRange 1..n
end
defp _fizzbuzzNoCondRange(b..b) do
_fizzbuzzNoCond rem(b,3), rem(b,5), b
end
defp _fizzbuzzNoCondRange(a..b) do
_fizzbuzzNoCond rem(a,3), rem(a,5), a
_fizzbuzzNoCondRange (a+1)..b
@eibrahim
eibrahim / examples.exs
Created February 2, 2016 14:09
List subtraction and concatenation
def list_concat a,b do a ++ b end
def list_sub a,b do a -- b end
#you can test this in iex
list_concat2 = &(&1 ++ &2)
list_concat2.([1,2],[3,4])
list_sub2 = &(&1 -- &2)
list_sub2.([1,2,3,4], [3,9,8,2])
@eibrahim
eibrahim / examples.exs
Created February 2, 2016 14:10
Multiplier - a function returning a function
def multiplier x do &(&1*x) end
def multiplier2 x do
fn(y) ->
y * x
end
end