Skip to content

Instantly share code, notes, and snippets.

@eibrahim
eibrahim / examples.exs
Created Feb 2, 2016
Multiplier - a function returning a function
View examples.exs
def multiplier x do &(&1*x) end
def multiplier2 x do
fn(y) ->
y * x
end
end
@eibrahim
eibrahim / examples.exs
Created Feb 2, 2016
List subtraction and concatenation
View examples.exs
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 Feb 2, 2016
Fizzbuzz without conditional logic
View examples.exs
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 Feb 2, 2016
Fizzbuzz with conditional logic
View examples.exs
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 / arraytransform.js
Created Sep 17, 2014
ArrayTransform EMber
View arraytransform.js
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 / MyEmberJsonMediaTypeFormatter.cs
Last active Dec 10, 2016
A JSON formatter for ASP.NET Web API to support Ember Data
View MyEmberJsonMediaTypeFormatter.cs
public class MyEmberJsonMediaTypeFormatter : JsonMediaTypeFormatter
{
private int _maxDepth = 256;
private JsonSerializerSettings _jsonSerializerSettings;
public MyEmberJsonMediaTypeFormatter()
{
_jsonSerializerSettings = CreateDefaultSerializerSettings();
}
public override System.Threading.Tasks.Task WriteToStreamAsync(System.Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
{
View gist.js
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 / chosen.js
Created Jun 6, 2013
Angular Directive for jQuery Chosen plugin. Usage: <select chosen=""></select>
View chosen.js
'use strict';
angular.module('frontendApp')
.directive('chosen', function ($timeout) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
var deferChosen = function(){
element.chosen({
View confirmButton.js
'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 / app.js.coffee
Created Apr 23, 2013
Angular safeApply helper
View app.js.coffee
$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
You can’t perform that action at this time.