Skip to content

Instantly share code, notes, and snippets.

View iStefo's full-sized avatar

Stefan Fochler iStefo

  • Munich, Germany
View GitHub Profile
# Requires Elixir 1.12+
Mix.install([
{:benchee, "~> 1.0"}
])
# Benchmark copied from https://gist.github.com/denispeplin/99047e34b0974b00116f335651d551d6
defmodule So.Exclude do
def exclude1() do
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
@iStefo
iStefo / countAndUpdateUI.swift
Last active April 28, 2018 20:15 — forked from jasonyunjoonpark/countAndUpdateUI.swift
completion handler for a function that takes a parameter
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.global(qos: .userInteractive).async {
//Background thread
@iStefo
iStefo / components.my-component.js
Created January 27, 2017 11:26
array-hash-fixed
import Ember from 'ember';
export default Ember.Component.extend({
totalLength: Ember.computed('data.@each.name', function() {
// doesn't matter, won't compute anyway
return -1;
})
});
import Ember from 'ember';
export default Ember.Component.extend({
totalLength: Ember.computed('data.@each.name', function() {
// doesn't matter, won't compute anyway
return -1;
})
});
@iStefo
iStefo / History.ex
Last active July 21, 2016 23:29
Learning Elixir: Transaction History Properties
defmodule History do
@type op :: {ta(), cmd(), data()}
@type ta :: any()
@type cmd :: :read | :write | :commit | :abort
@type data :: any()
@doc """
Parses a textual representation of a history into a list of operation tuples.
## Examples
@iStefo
iStefo / escapeExpression.js
Created March 19, 2015 13:10
Handlebars escapeExpression for Spacebars
/*
escapeExpression inserted into the Spacebars namespace, taken from
https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/utils.js
*/
var escape = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",

"Model-dependent query param stickiness"

The question of whether query param controller properties are preserved/restored/reset when navigating away/back/between routes is a tricky one, but the sensible default seems to be "model-dependent stickiness", whereby query params are stick unless you're switching the model of the current or parent routes. There's more that could be said about this but here's a quick summary of my plan:

  • We need a dictionary to store QP state scoped to a model
@iStefo
iStefo / gist:9267640
Created February 28, 2014 08:54
my thoughts on query-params-new

These are my thoughts on using the (bleeding edge) query-params-new from 1.6.0-beta.1+canary.01f3f32c.

1. Numerical Parameters

The currently handled parameter types are strings (of course), arrays (with the arr[]=foo1&arr[]=foo2 syntax, which is not the nicest but closest zu the standard) and booleans. The absence of integer parameters means having to use parseInt() in every method where the parameter is used. (Setting the parameter to a number value is no problem)

I think there are two ways to determine whether to cast or not while parsing parameters:

  1. Check if param contains only digits and just assume that it's meant to be a numeric parameter then. Since this may cause unforeseen behaviour we shouldn't do this
  2. Add a descriptior to the controllers queryParams to force a query parameters data type (this would also allow providing an array when the present url is arr=foo1 without the [], but I'm not sure if this is a desirable thing)
@iStefo
iStefo / ember-meta.js
Created April 29, 2013 13:14
Ember-Meta module. See first comment for usage etc.!
// include this code in your application, you don't need to call any initialization manually!
Ember.Application.initializer({
name: "meta",
initialize: function(container, application) {
// helper function to get tag from dom
var _getTag = function(tagname, property, value) {
var tags = document.head.getElementsByTagName(tagname),
tag,