Skip to content

Instantly share code, notes, and snippets.

View joeriks's full-sized avatar
💭
I may be slow to respond.

Jonas Eriksson joeriks

💭
I may be slow to respond.
View GitHub Profile
@joeriks
joeriks / hyperhtml.html
Created May 20, 2018 21:51
hyperhtml and babel sample (for IE)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://unpkg.com/hyperhtml@2.10.1/min.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if
@joeriks
joeriks / sample_template.cs
Last active June 15, 2016 11:24
Vanilla templating with string interpolation
private string TemplateTable(Dictionary<string, string> dict)
{
var rowTemplate = new Func<string, string, string>((key, value) => $"<tr><td>{key}</td><td>{value}</td></tr>");
return $"<table>{String.Join(Environment.NewLine, dict.Select(t => rowTemplate(t.Key, t.Value)))}</table>";
}
private string PageTemplate(SomeModel model)
{
var liTemplate = new Func<string, string, string>((key, value) => !string.IsNullOrEmpty(value) ? $"<li><strong>{key}</strong>{value}</li>" : "");
return $@"<html>
@joeriks
joeriks / structure_and_content_creation_script.cshtml
Created March 27, 2015 10:59
Poor mans "Code First" implementation for Umbraco - or rather a sample of a Structure and Content creation script
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}
@functions{
/*
* Poor mans "Code First" implementation for Umbraco
@joeriks
joeriks / map_stringlines_to_anon.cs
Last active August 29, 2015 14:17
Map multiline string to array of anonymous objects using linq
var structure = @"
Alias Document name Parent
---------------------------------
root Root DocType -1
textType Text DocType 0
";
var mapped = Regex.Split(structure, @"\r\n", RegexOptions.IgnorePatternWhitespace) /* split string into lines */
@joeriks
joeriks / program.cs
Last active August 29, 2015 14:11
fun with delegates, expressive namings, pipe forwards, func di and auto-method-name-logging in C#
using System;
using System.Reflection;
public class Program
{
static void Main(string[] args)
{
// setup db and logger using funcs
@joeriks
joeriks / anonZeroHtml.cs
Last active August 29, 2015 14:09
the zero locs html template . anonymous types
public Func<string, string> tag(string tag)
{
return new Func<string, string>(s =>
{
return string.Format("<{0}>{1}</{0}>", tag, s);
});
}
public Func<string, string> tagAttr(string tag, string attrName)
{
@joeriks
joeriks / GetCreateAndShipOrder.cs
Created October 27, 2014 12:51
Merchello step
public object GetCreateAndShipOrder(string userName, string productSku)
{
// get product
var product = _merchelloContext.Services.ProductService.GetAll().FirstOrDefault(p => p.Sku == productSku);
// get customer
var customer = _merchelloContext.Services.CustomerService.GetByLoginName(userName);
// create customer with fake data if it does not exist already
if (customer == null)
@joeriks
joeriks / azure-vm-start.ps1
Created October 22, 2014 08:25
Azure Powershell to start, stop and remote desktop into VMs
function stopvm($azurecloud,$vmname)
{
if ($vmname -eq $null)
{
Get-AzureVM -ServiceName $azurecloud |Foreach-object {Stop-AzureVM -ServiceName $_.ServiceName -Name $_.Name -Force}
}
else
{
Stop-AzureVM -ServiceName $azurecloud -Name $vmname
}
@joeriks
joeriks / sampleclass.ts
Created October 17, 2014 07:14
explicitly use "public" function access modifier in Typescript
class Greeter {
// Hard to see which ones of these are function declarations
// and which ones are function calls:
greet0() {
// do something...
}
greet1(){
greet2({
// can you spot the difference?