Skip to content

Instantly share code, notes, and snippets.

View aeinbu's full-sized avatar

Arjan Einbu aeinbu

View GitHub Profile
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){
// traditional version
function toggleValueInArray1(val, arr) {
var ix = arr.indexOf(val);
if(ix === -1){
// add to array
arr.push(val);
}
else
{
// remove from array
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);
});
@aeinbu
aeinbu / RedisExtensions.cs
Created September 28, 2015 13:16
Simple extension to make it easier to use Redis Caching and StackExchange.Redis package
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);
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];
@aeinbu
aeinbu / cookieCutter.js
Last active November 15, 2015 14:59
A small utility to read ASP.NET issued cookies from javascript. (Cookies and sub-cookies)
;(function(){
function cookieCutter(cookieName, subCookieName) {
var name = cookieName + "=";
if (subCookieName) {
name += subCookieName + "=";
}
var cookie = document.cookie + ";";
var cookieValueStart = cookie.indexOf(name) + name.length;
var val = cookie.substring(cookieValueStart, cookie.indexOf(";", cookieValueStart));