Skip to content

Instantly share code, notes, and snippets.

View aurbano's full-sized avatar
🎯
ML

Alejandro U. Alvarez aurbano

🎯
ML
View GitHub Profile
@aurbano
aurbano / regex.md
Last active October 27, 2016 14:11
Match a word preceded by specific words, but not others, and with optional appendixes

Regex

((pre1)|pre2)?(?(1)\s)(?<!notallowed )main word(?(2)-appendix1)

This will match

pre1 main word-appendix1 pre2 main word

<!DOCTYPE html>
<html><head>
<title>Obfuscated name remapper</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
background: white;
color: black;
font-family: "Trebuchet MS",Helvetica,Tahoma,Arial,sans-serif;
font-size: 90.01%;
// Sift4 - extended version
// online algorithm to compute the distance between two strings in O(n)
// maxOffset is the number of positions to search for matching tokens
// options: the options for the function, allowing for customization of the scope and algorithm:
// maxDistance: the distance at which the algorithm should stop computing the value and just exit (the strings are too different anyway)
// tokenizer: a function to transform strings into vectors of tokens
// tokenMatcher: a function to determine if two tokens are matching (equal)
// matchingEvaluator: a function to determine the way a token match should be added to the local_cs. For example a fuzzy match could be implemented.
// localLengthEvaluator: a function to determine the way the local_cs value is added to the lcss. For example longer continuous substrings could be awarded.
// transpositionCostEvaluator: a function to determine the value of an individual transposition. For example longer transposi
@aurbano
aurbano / inlineConfirm.js
Created August 7, 2015 12:36 — forked from markthiessen/inlineConfirm.js
AngularJS (+Bootstrap) directive for inline ngClick confirmation
(function () {
'use strict';
angular.module('yourModule', []).directive('inlineConfirm',
['$compile',
function ($compile) {
return {
priority: -100,
link: function (scope, elm, attrs) {
var wrapperTemplate = '<div class="popover inline-confirm" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>';
var template =
@aurbano
aurbano / joinArrays.js
Created July 2, 2015 14:54
Join two normalized arrays using a join table, returning a copy of the first array containing a property with an array of mapped elements of arr2
/**
* Join two normalized arrays using a join table, returning a copy of
* the first array containing a property with an array of mapped
* elements of arr2
*
* @see normalizeArrayId
*
* @param arr1 Normalized array 1
* @param arr2 Normalized array 2
* @param arrJoin Array with the joins
@aurbano
aurbano / normalizeArrayId.js
Created July 2, 2015 14:53
Given an array of objects that have an Id, return an array where the Id is the key
/**
* Given an array of objects that have an Id, return an array where the Id is the key
* @param arr Array to normalize
* @param key [Optional] Object key to use, defaults to Id
* @returns {Array} Normalized array
*/
function normalizeArrayId(arr, key){
var total = arr.length,
index = key || 'Id',
ret = [];
@aurbano
aurbano / removeKeys.js
Last active November 29, 2022 21:57
Remove a property from a nested object, recursively
/**
* Remove all specified keys from an object, no matter how deep they are.
* The removal is done in place, so run it on a copy if you don't want to modify the original object.
* This function has no limit so circular objects will probably crash the browser
*
* @param obj The object from where you want to remove the keys
* @param keys An array of property names (strings) to remove
*/
function removeKeys(obj, keys){
var index;
@aurbano
aurbano / htmlEncode.js
Created May 1, 2015 11:49
HTML Encode content easily, requires jQuery
function htmlEncode(value){
// Create a in-memory div, set it's inner text(which jQuery automatically encodes)
// then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
@aurbano
aurbano / angularDraggable.js
Created April 20, 2015 12:23
Angular Draggable directive, with support for dragging another element, and container
angular.module('aurbano.draggable', [])
.directive('draggable', ['$document', function($document) {
return {
scope: {
config: '=draggable'
},
link: function(scope, element, attr) {
var dragElement = element;
if(scope.config.target){
if(scope.config.target === 'parent'){
@aurbano
aurbano / httpResource.js
Created April 18, 2015 11:07
AngularJS returning data from an endpoint as a resource
angular.module('serviceName', [])
.factory('resourceName', ['$resource',
function($resource) {
var status = $resource('/endpoint');
return status.get().$promise;
}
]);