Skip to content

Instantly share code, notes, and snippets.

View IlanFrumer's full-sized avatar

Ilan Frumer IlanFrumer

  • Israel , Nahariya
View GitHub Profile
@IlanFrumer
IlanFrumer / ConsoleScripts.js
Last active December 14, 2015 05:49
Append needed script tags to documents
defaultSource = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
// just uncomment the library that you need ( and keep the others commented )
// scriptSource = '//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.min.js';
// scriptSource = '//cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js';
// scriptSource = '//cdn.jsdelivr.net/sugar/1.3.9/sugar.min.js';   
// scriptSource = '//cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js';
// http://stackoverflow.com/questions/6690752/insert-html-at-cursor-in-a-contenteditable-div
function pasteHtmlAtCaret(html) {
var sel, range;
if (window.getSelection) {
// IE9 and non-IE
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
window.requestAnimationFrame ||=
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
(callback, element) ->
window.setTimeout( ->
callback(+new Date())
, 1000 / 60)
@IlanFrumer
IlanFrumer / fuzzysearch.coffee
Created April 22, 2013 15:54
Fuzzy Search
# http://stackoverflow.com/questions/9206013/javascript-fuzzy-search#answer-15252131
String.prototype.fuzzy = (search) ->
return true unless search
str = @toLowerCase()
search = search.toLowerCase()
i = 0
@IlanFrumer
IlanFrumer / minification-safe-angularjs-di.coffee
Created October 2, 2013 07:12
AngularJS's DI system inspects function parameters to determine what to inject. JavaScript minifiers rename (mangle) function parameters. To overcome this, AngularJS has a "minifier-safe inline" notation.
app = angular.module('app',[])
app.controller 'myCtrl1' , ['$scope','$http','$location', ($scope, $http,$location)->
$scope.data = {}
]
app.controller 'myCtrl2' , ['$scope','$http','$location'].push ($scope, $http,$location)->
$scope.data = {}
@IlanFrumer
IlanFrumer / markdownLink.coffee
Last active December 24, 2015 21:39
angular.js directive for transforming simple list to hyperlinks
@IlanFrumer
IlanFrumer / sortByDependencies.php
Last active December 25, 2015 18:29
sorting array of dependencies
function sortByDependencies(array $array){
$solved_dependencies = array();
while(!empty($array))
{
$tmp_list = array();
foreach ($array as $key => $dependencies) {
detectLanguage = ->
lang = undefined
lang = lang[1] if navigator and navigator.userAgent and (lang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))
if not lang and navigator
if navigator.language
lang = navigator.language
else if navigator.browserLanguage
lang = navigator.browserLanguage
else if navigator.systemLanguage
lang = navigator.systemLanguage
@IlanFrumer
IlanFrumer / uiSrefClassDirective.coffee
Last active December 30, 2015 05:49
Use with angular.js UI-Router directive ui-sref
# <a ui-sref="mystate" ui-sref-class="active">link</a>
#
# whenever the current state is 'mystate' a class of 'active' will be added to the same element.
angular.module('ui-sref-class',[])
.directive "uiSrefClass", ->
link: (scope, elm , attrs)->
scope.$on '$stateChangeSuccess' , (event, toState)->
if toState.name == attrs.uiSref
elm.addClass(attrs.uiSrefClass)
@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];