Skip to content

Instantly share code, notes, and snippets.

View IlanFrumer's full-sized avatar

Ilan Frumer IlanFrumer

  • Israel , Nahariya
View GitHub Profile
app.directive('repeatStyle', function(){
var classes = [
'first : $first',
'last : $last',
'middle : $middle',
'odd : $odd',
'even : $even'
].join(', ');
app.factory('timeout', ['$timeout',
function($timeout){
return function $timeoutFactory(){
var promise = null;
function timeout (fn, delay, invokeApply){
$timeout.cancel(promise);
promise = $timeout(function(){
fn();
promise= null;
}, delay, invokeApply);
app.filter "$json", ->
(obj, spaces = 2) ->
JSON.stringify obj, null, spaces
app.directive 'confirmBox', ($templateCache, $compile, $animate, $timeout)->
controller: ($element, $scope, $attrs)->
contents = $element.contents()
dialog = null
action = null
timeout = null
open: (options)->
@IlanFrumer
IlanFrumer / contenteditable.coffee
Created February 3, 2014 08:46
ngModel + contenteditable support for angular.js
app.directive "contenteditable", ->
require: "?ngModel"
link: (scope, element, attrs, ngModel) ->
if(ngModel)
# view -> model
element.bind "blur", ->
scope.$apply ->
ngModel.$setViewValue(element.html())
# model -> view
@IlanFrumer
IlanFrumer / ui-router-trailing-slash.coffee
Last active August 29, 2015 13:55
ui router - trailing slash
app.config ($urlRouterProvider)->
##############################################################################################################################
# https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-make-a-trailing-slash-optional-for-all-routes
##############################################################################################################################
$urlRouterProvider.rule ($injector, $location)->
path = $location.path()
@IlanFrumer
IlanFrumer / uiSrefParams.js
Created January 6, 2014 11:34
Angular.js ui-router directive to Reload current state with different params
app.directive("uiSrefParams", function($state) {
return {
link: function(scope, elm, attrs) {
var params;
params = scope.$eval(attrs.uiSrefParams);
return elm.bind("click", function(e) {
var button;
if (!angular.equals($state.params, params)) {
button = e.which || e.button;
if ((button === 0 || button === 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
Faker = require 'Faker'
mongoose = require 'mongoose'
UserSchema = new mongoose.Schema {
_id: String
name: String
}
User = mongoose.model('User', UserSchema)
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON("package.json")
sass:
options:
includePaths: ["bower_components/foundation/scss"]
dist:
options:
outputStyle: "compressed"
@IlanFrumer
IlanFrumer / PDOExceptionExtractor.php
Created December 10, 2013 10:51
extracts PDOException error code & message from error message
<?php
preg_match('/^SQLSTATE\[\w+\]:[^:]+:\s*(\d*)\s*(.*)/', $error->getMessage(), $matches) ||
preg_match('/^SQLSTATE\[\w+\]\s*\[(\d+)\]\s*(.*)/', $error->getMessage(), $matches);
$code = $matches[1] ?: "0" ;
$message = $matches[2];