Skip to content

Instantly share code, notes, and snippets.

View rexm's full-sized avatar

Rex Morgan rexm

View GitHub Profile
var basicTestTemplate = "{{mycustomhelper Person.Address.City}}";
var blockTestTemplate = "{{#mycustomblock Person.FirstName}} Hello world {{/mycustomblock}}";
Handlebars.Handlebars.RegisterHelper (
"mycustomhelper",
(writer, context, arguments) => writer.Write (arguments [0]));
Handlebars.Handlebars.RegisterHelper (
"mycustomblock", (writer, options, context, arguments) => {
options.Template(writer, (object)context);
@rexm
rexm / gist:89ee239fda36799ece0e
Created January 10, 2015 15:50
Perf testing Handlebars.Net vs Regex for different object types
class MainClass
{
private static readonly Regex HbRegex = new Regex("(?<replaceGroup>{{[^}]*}})", RegexOptions.Compiled);
public static void Main (string[] args)
{
var str = "This is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}"
+ "This is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}"
+ "This is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}"
+ "This is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}, and this is {{Test}} of {{This}}";
public static ISimpleDbItem Add<T>(this ISimpleDbItemCollection collection, string name, T entity)
{
return collection.Add(name,
entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(
p => attributeTypes.Contains(p.PropertyType) &&
p.GetIndexParameters().Length == 0)
.ToDictionary(
p => p.Name,
p => (SimpleDbAttributeValue)p.GetValue(entity, null)));
AppDomain.AssemblyLoad += (sender, args) => {
var regType = args.LoadedAssembly.GetType("UnityRegistration");
if(regType != null){
activator.CreateInstance(regType, rootUnityContainer);
}
}
@rexm
rexm / Example usage
Created July 27, 2014 23:01
A binding for inline editable text.
<span data-bind="editableText: myText"></span>
<script type="text/javascript">
var vm = {
myText: ko.observable('Hello, world!')
};
ko.applyBindings(vm);
</script>
@rexm
rexm / Example A
Created March 24, 2014 15:01
JavaScript tech screen: 1) what's the difference? 2) why?
function moduleA() {
var viewModel = {
activate: activate
};
function activate() {
//init
}
@rexm
rexm / gist:7324292
Last active December 27, 2015 12:18
/* Chosen v1.0.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;zoom:1;*display:inline;-webkit-user-select:none;-moz-user-select:none;user-select:none}.chosen-container .chosen-drop{position:absolute;top:100%;left:-9999px;z-index:1010;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15)}.chosen-container.chosen-with-drop .chosen-drop{left:0}.chosen-container a{cursor:pointer}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:23px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),color-stop(100%,#f4f4f4));background:-webkit-linear-gradient(top,#fff 20%
@rexm
rexm / gist:7324237
Last active December 27, 2015 12:09
/* Chosen v1.0.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
!function(){var a,AbstractChosen,Chosen,SelectParser,b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),children:0,disabled:a.disabled}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.p
@rexm
rexm / gist:5871642
Last active December 19, 2015 00:49 — forked from rickschott/gist:5870724
var MyBigVM = function (options) {
var $koThis = this;
var map = {
Items: {
create: function(options) {
var item = ko.mapping.fromJS(options.data);
item.blaComputed = ko.computed(function () {
return this.bla1() + " / " + this.bla12();
}, item);
return item;