Skip to content

Instantly share code, notes, and snippets.

@cgmartin
cgmartin / datepicker.decorator.js
Last active May 21, 2018 21:42
Send an event to refresh view of ui-bootstrap datepicker
/**
* Decorates the ui-bootstrap datepicker directive's controller to allow
* refreshing the datepicker view (and rerunning invalid dates function)
* upon an event trigger: `$scope.$broadcast('refreshDatepickers');`
*
* Works with inline and popup. Include this after `ui.bootstrap` js
*/
angular.module('ui.bootstrap.datepicker')
.config(function($provide) {
$provide.decorator('datepickerDirective', function($delegate) {
@cgmartin
cgmartin / gist:10328349
Last active August 29, 2015 13:58
grunt-newer: Check for newer @import .less files
//
// grunt-newer:
// Check for newer @import .less files example
// See: https://github.com/tschaub/grunt-newer/issues/29
//
grunt.initConfig({
// ...
newer: {
options: {
override: function(taskName, targetName, filePath, time, include) {
Memcache serialization test (ext/memcache v2.2.7)
*** unsetKey ***
bool(false)
*** emptyKey ***
string(0) ""
*** falseKey ***
string(0) ""
@cgmartin
cgmartin / api_models_ModelA.js
Created January 10, 2014 04:21
Separate mysql db adapter test with Sails.js
module.exports = {
adapter: 'mysqlDb1',
attributes: {
name: 'string'
}
};
@cgmartin
cgmartin / browser-output.txt
Last active December 21, 2015 11:58
Long running WAMP RPC call with progress status events
Long Run Button clicked
WAMP client initialized
WAMP connected 1377136104011-1
status:long-run RECEIVED 0
status:long-run RECEIVED 1
status:long-run RECEIVED 2
status:long-run RECEIVED 3
status:long-run RECEIVED 4
status:long-run RECEIVED 5
status:long-run RECEIVED 6
@cgmartin
cgmartin / gist:6050892
Created July 22, 2013 02:07
Default VM settings
$ java -XX:+PrintFlagsFinal
[Global flags]
uintx AdaptivePermSizeWeight = 20 {product}
uintx AdaptiveSizeDecrementScaleFactor = 4 {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}
uintx AdaptiveSizePausePolicy = 0 {product}
uintx AdaptiveSizePolicyCollectionCostMargin = 50 {product}
uintx AdaptiveSizePolicyInitializingSteps = 20 {product}
uintx AdaptiveSizePolicyOutputInterval = 0 {product}
uintx AdaptiveSizePolicyWeight = 10 {product}
@cgmartin
cgmartin / gist:5990806
Created July 13, 2013 14:01
noir validation example
(ns my.routes.auth
(:use compojure.core
[hiccup.util :only (url to-str)])
(:require [ring.util.response :as response]
[taoensso.tower :as t]
[noir.session :as session]
[noir.cookies :as cookies]
[noir.validation :as vali]
[noir.util.crypt :as crypt]))
var sess;
ab.connect(
// ...
function (session) { // Connection callback
// Authenticate
var username = 'guest';
var password = 'secret-password';
// send authreq rpc call
(defn rpc-url [path] (str "http://wamptutorial/rpc#" path))
(defn evt-url [path] (str "http://wamptutorial/event#" path))
(defn auth-secret [sess-id auth-key extra]
"secret-password") ; from database
(defn auth-permissions [sess-id auth-key}
; get permissions for this user
{:rpc {(rpc-url "echo") true}
:subscribe {(evt-url "chat") true}
@cgmartin
cgmartin / gist:5880732
Last active September 15, 2018 01:22
WebSocket subprotocol and origin validation with HTTP Kit
(ns my.server
(:use org.httpkit.server
[clojure.string :only [split trim lower-case]])
(:import [org.httpkit.server AsyncChannel]))
(defn origin-match? [origin-re req]
(if-let [req-origin (get-in req [:headers "origin"])]
(re-matches origin-re req-origin)))