Skip to content

Instantly share code, notes, and snippets.

View dalgard's full-sized avatar

Kristian Dalgård dalgard

  • Various Productions
  • Aarhus, Denmark
View GitHub Profile
@dalgard
dalgard / extendDeep.js
Created April 26, 2014 15:24
Method for deep (recursive) extension of a given object with the properties of passed-in object(s) with support for standards-compliant getters and setters
function extendDeep(target) {
// Run through rest parameters
Array.prototype.slice.call(arguments, 1).forEach(function (source) {
if (typeof target === "object") {
if (typeof source === "object") {
// If source is an array, only copy enumerable properties
var keys = (Array.isArray(source) ? Object.keys(source) : Object.getOwnPropertyNames(source));
// Iterate over keys
keys.forEach(function (key) {
@dalgard
dalgard / _checkbox_method.scss
Last active February 16, 2016 21:45
Sass mixin to help put 'the checkbox hack' (which I rather consider a 'technique') to good use. This version requires a media mixin, e.g. from Neat
@mixin toggled($selector, $media...) {
#{unquote($selector)}:checked ~ & {
@if length($media) > 0 {
@include media($media...) {
@content;
}
}
@else {
@content;
}
@dalgard
dalgard / custom-fields.js
Last active September 22, 2017 07:08
(Meteor) Customizing field layout in useraccounts:semantic-ui with the use of aldeed:template-extension
// Adding some simplistic fields
AccountsTemplates.addFields([
{
_id: "address",
type: "text",
// Options object with custom properties for my layout
options: {
// Put a divider before this field
dividerBefore: true
@dalgard
dalgard / Sublime.md
Last active September 11, 2015 09:25

Sublime Text 3 preferences

My personal setup in OS X – for future reference.

Keyboard shortcuts

Key Action
Cmd + left/right Home/End
@dalgard
dalgard / peopleMock.json
Last active July 21, 2022 20:10
JSON list of people (https://mockaroo.com/)
[{"id":1,"first_name":"Gary","last_name":"Ortiz","email":"[email protected]","country":"Indonesia","modified":"2015-05-16","vip":false},
{"id":2,"first_name":"Albert","last_name":"Williamson","email":"[email protected]","country":"China","modified":"2015-03-11","vip":true},
{"id":3,"first_name":"Mildred","last_name":"Fuller","email":"[email protected]","country":"Peru","modified":"2015-02-15","vip":true},
{"id":4,"first_name":"Russell","last_name":"Robinson","email":"[email protected]","country":"Belarus","modified":"2014-10-31","vip":false},
{"id":5,"first_name":"Laura","last_name":"Harper","email":"[email protected]","country":"Philippines","modified":"2015-01-14","vip":false},
{"id":6,"first_name":"Larry","last_name":"Sanders","email":"[email protected]","country":"China","modified":"2015-01-11","vip":false},
{"id":7,"first_name":"Michael","last_name":"Rice","email":"[email protected]","country":"Philippines","modified":"2014-12-06","vip":true},
{"id":8,"first_name":"Sara","last_name":"Harris",
<template name="openModal">
<button class="button" {{bind 'openModal: myModalTemplate'}}>Open modal</button>
</template>
// Override the original behaviour from sewdn:collection-behaviours
CollectionBehaviours.defineBehaviour("trackable", function (getTransform, args) {
if (_.isArray(args[0]))
args = args[0];
// Track all updated fields or only a list of fields
if (args[0] === true) {
var track_field = args[1] || "updatedTrack",
slice = false;
# This regex throws away anything between quotes at the root level, and captures
# anything between parentheses preceded by a keyword at the root level
# It uses this technique: http://www.rexegg.com/regex-best-trick.html
/
(?: # Group
( \1 # Capturing group
['"] # Quotation mark
)
// Return the last truthy argument
Template.registerHelper("and", (...args) => _.reduce(popkw(args), (memo, item) => memo && item));
// Return the first truthy argument
Template.registerHelper("or", (...args) => _.reduce(popkw(args), (memo, item) => memo || item));
// Return whether all arguments are strictly equal
Template.registerHelper("is", (...args) => compareLeft(popkw(args), (a, b) => a === b));
// Return whether each argument is greater than the previous
{
"folders":
[
{
"file_exclude_patterns":
[
"*.sublime-workspace",
"*.map",
"*.min.*"
],