Skip to content

Instantly share code, notes, and snippets.

View krawaller's full-sized avatar

David Waller krawaller

View GitHub Profile
<!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>
<style>
.done {
background-color: #DDD;
@krawaller
krawaller / object.js
Created November 1, 2017 12:37
object lookup examples
var me = {
name: "David Waller",
nickName: "Davve",
prop: "kopp"
};
var formalSituation = true;
var prop;
@krawaller
krawaller / components.ts
Created July 25, 2017 14:31
Angular components as table rows
import { Component, Input } from '@angular/core';
@Component({
selector: 'app',
template: `
<table>
<tr magicrow msg="hello"></tr>
<tr magicrow msg="world"></tr>
</table>
`,
@krawaller
krawaller / typedcontainers.md
Last active May 13, 2017 05:52
typed connect

To create a container, I only need to add my AppState typings to the mapStateToProps parameter:

const mapStateToProps = (state: State) => ({
  messages: state.messaging.messages
});

const mapDispatchToProps = (dispatch) => ({
  dismissUIMessage: (num) => dispatch(actions.dismissUIMessage(num))
});
@krawaller
krawaller / firebase.md
Created May 9, 2017 05:08
Enforcing Firebase relation validity

Say we have a database of users and roles, where each user belongs to a role. Using the denormalized Firebase approach I might store that like this:

{
  "users": {
    "abc123": {
      "name": "Joe",
      "role": "kkk333"
    },
    // lots more users
@krawaller
krawaller / ng.html
Created May 10, 2016 14:33
fun fun angular stuff :)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 1</title>
<style>
.done {
text-decoration: line-through;
}
@krawaller
krawaller / exercise1.html
Last active May 10, 2016 11:25
angular cheating
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 1</title>
<script src="../jquery.js"></script>
<script src="../angular.js"></script>
<style>
.selected {
text-decoration: line-through;
@krawaller
krawaller / myapp.js
Created February 16, 2016 16:01
Weird
angular.module('myApp',[])
.factory('tags',function(){
var tags = ['urgent','blocked','boring','hard'],
callbacks = [];
return {
addTag: function(t){
tags.push(t);
callbacks.forEach(function(cb){
cb(tags)
@krawaller
krawaller / directives.md
Last active January 27, 2016 08:03
Grokking angular by claims
  • ng-submit * only makes sense on a <form> tag * is just an event handler much like ng-click
  • ng-options * only makes sense on a <select> tag * enables us to have objects as selected values instead of just strings * saves us from having to type out <options ng-repeat="..." ... /> * provides additional shortcut for <optgroup> through :groupBy
  • ng-click
  • should always be a method call, don't do assignments as that relies on brittle scoping and is hard to test
@krawaller
krawaller / glyphtxt.js
Last active December 28, 2015 14:29
Convenience function for using Glyphicons in flowing text, allowing size and colour to follow from the surroundings.
txticon = function(iconname) {
var map = {
"glass": "E001",
"leaf": "E002",
"dog": "1F415",
"user": "E004",
"girl": "1F467",
"car": "E006",
"user_add": "E007",
"user_remove": "E008",