This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const angular = require("angular"); | |
angular | |
.module("modulename") | |
.directive('attachFocusFunction', function($parse) { | |
return { | |
scope: false, | |
link(scope, element, attributes) { | |
let expr = $parse(attributes.attachFocusFunction); | |
if(!expr.assign){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const angular = require("angular"); | |
const _ = require("lodash"); | |
angular | |
.module("modulename") | |
.directive("componentBinder", function($compile, $parse) { | |
return { | |
restrict: "E", | |
scope: { | |
componentName: "<", | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to turn node style functions with callbacks into promises. | |
// This is useful when using async/await, since promises can be awaited upon. | |
const callback = (resolve, reject) => (err, res) => err ? reject(err) : resolve(res); | |
const awaitable = async action => new Promise((resolve, reject) => action(callback(resolve, reject))) | |
module.exports = awaitable; | |
// Usage: | |
// const fs = require("fs"); | |
// const awaitable = require("./awaitable"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([], function () { | |
"use strict"; | |
function parse(querystring) { | |
var obj = {}; | |
if (querystring) { | |
var params = querystring.split(/&|\?/); | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using StackExchange.Redis; | |
namespace ConsoleApplication1 | |
{ | |
public static class RedisExtensions | |
{ | |
public static RedisValue Get(this IDatabase db, RedisKey key, Func<RedisValue> loadFunc, TimeSpan slidingDuration) | |
{ | |
var ret = db.StringGet(key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ko from 'knockout'; | |
import $ from 'jquery'; | |
var templateFromUrlLoader = { | |
loadTemplate(name, templateConfig, callback) { | |
if (templateConfig.fromUrl) { | |
var fullUrl = templateConfig.fromUrl; | |
$.get(fullUrl, markupString => { | |
ko.components.defaultLoader.loadTemplate(name, markupString, callback); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// traditional version | |
function toggleValueInArray1(val, arr) { | |
var ix = arr.indexOf(val); | |
if(ix === -1){ | |
// add to array | |
arr.push(val); | |
} | |
else | |
{ | |
// remove from array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrapInReadOnlyProxy(orig, throwOnSet = false) { | |
if (typeof orig !== "object") { | |
return orig; | |
} | |
return new Proxy(orig, { | |
get: function(target, property) { | |
if (property in target) { | |
return wrapInReadOnlyProxy(target[property]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combinePredicates = (predicate1, predicate2, ...predicateRest) => | |
(item) => | |
predicate1(item) && (predicateRest.length > 0? combinePredicates(predicate2, predicateRest[0]): predicate2)(item); | |
// sample predicates | |
const exclude = (val) => (item) => item !== val; | |
const excludeRange = (from, to) => (item) => item < from || item > to; | |
// sample data | |
let arr = [1,2,3,4,5,6,7,8,9,10]; |
OlderNewer