Skip to content

Instantly share code, notes, and snippets.

View bobjackman's full-sized avatar

Bob Jackman bobjackman

View GitHub Profile
@bobjackman
bobjackman / SomeClass.dart
Created February 4, 2020 20:15
Set value only if we don't already have one
class SomeClass {
String foobar;
void someMethod(String newValue) {
if (foobar == null) {
foobar = newValue;
}
}
// OR //
@bobjackman
bobjackman / SomeClass.dart
Created February 4, 2020 20:10
Making fromMap Constructors Require Certain Fields
class SomeClass {
String id;
String foo;
String bar; // required
String zap; // required
SomeClass.fromMap(Map<String, dynamic> inputMap) {
this.id = inputMap['ID'];
this.foo = inputMap['Foo'];
this.bar = inputMap['Bar'];
@bobjackman
bobjackman / SomeClass.dart
Created February 4, 2020 19:49
Dart Read-Only Properties
class SomeClass {
String _foobar;
String get foobar => _foobar;
// note: no setter defined = can't write new values
SomeClass(this._foobar);
}
@bobjackman
bobjackman / LN Coding Standards - Dart
Created January 4, 2018 22:57
LN Coding Standards - Dart
# Dart Coding Standards - LiveNinja Development
## Conventions
The key words `MUST`, `MUST NOT`, `REQUIRED`, `SHALL`, `SHALL NOT`, `SHOULD`, `SHOULD NOT`, `RECOMMENDED`, `MAY`, and `OPTIONAL` in this document are to be interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) and summarized as follows:
1. `MUST` This word, or the terms `REQUIRED` or `SHALL`, mean that the definition is an absolute requirement of the specification.
1. `MUST NOT` This phrase, or the phrase `SHALL NOT`, mean that the definition is an absolute prohibition of the specification.
1. `SHOULD` This word, or the adjective `RECOMMENDED`, mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.
// DON'T DO THIS
if ((user != null && user.id.isNotEmpty && targetId == user.id) || (user.name.isNotEmpty ? user.name : '') == targetName || (phoneNumber.isNotEmpty && phoneNumber == user.phoneNumber)) {
  //...;
}

// DON'T DO THIS
if (
  (user != null && user.id.isNotEmpty && targetId == user.id)
 || (user.name.isNotEmpty ? user.name : '') == targetName
@bobjackman
bobjackman / handlebars-select-helper.js
Last active March 23, 2016 23:57 — forked from LukeChannings/handlebars-select-helper.js
A select helper for handlebars
Handlebars.registerHelper( 'select-options', function( items, selectedValue, options ) {
// ======== Ensure `items` is Object/Hash
if( items instanceof Array ) {
var temp = {};
for( var i in items ) {
var value = items[i];
temp[value] = value;
}
items = temp;
}
@bobjackman
bobjackman / gist:8925801
Last active August 29, 2015 13:56
Git one-liners to detect improper use of git-flow during release.
  • Show number of commits that exist in develop, but NOT in the current branch (is my branch sync’d with develop? Should return 0)
    git rev-list HEAD..origin/develop --no-merges | wc –l
  • Show number of commits that exist in develop, but NOT in master or vice-versa (have master and develop diverged?)
    • (have master and develop diverged in some way? Irrespective of current branch – should return 0)
      git rev-list origin/develop...origin/master --no-merges | wc -l
    • (does develop have anything not in master? Irrespective of current branch – should return 0)
      git rev-list origin/develop..origin/master --no-merges | wc –l
    • (does master have anything not in develop? Irrespective of current branch)
      • (just a total number of commits – should return 0)
        git rev-list origin/master..origin/develop--no-merges | wc –l
@bobjackman
bobjackman / git-stats
Last active July 12, 2018 13:52
Get a summary of total LOC added, removed, gross line changes, && net total LOC. Credit to (alex)[http://stackoverflow.com/users/887836/alex] modified by (kogi)[http://stackoverflow.com/users/84762/kogi]
#!/usr/bin/env bash
# usage:
# git-stats #gives stats for the whole branch
# git-stats --author="yourname here" #gives stats for specific author
#
# though not all tested, this should be compatible with all limiting options supported by git-log (https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_commit_limiting)
git log --pretty=tformat: --numstat $@ "`git merge-base HEAD develop`..HEAD" | gawk '{ adds += $1 ; subs += $2 ; net += $1 - $2 ; gross += $1 + $2 ; commits += 1 } END { print "total commits\tadded loc\tremoved loc\tgross loc\tnet loc\n"; printf "%d\t%d\t%d\t%d\t%d\n", commits, adds, subs, gross, net }' | column -s $'\t' -t
@bobjackman
bobjackman / myUnmerged.sh
Last active February 22, 2017 13:55
Find all branches that have unmerged commits authored by me. This is my first attempt at a bash script, so if you have suggestions for better/clearer/faster code, please let me know!
#!/usr/bin/env bash
# usage:
# local branches only: `myUnmerged`
# remote branches only: `myUnmerged -r`
# all branches: `myUnmerged -a`
#
# example output:
#
# BRANCH TOTAL COMMITS KOGI KOGI UNMERGED
@bobjackman
bobjackman / gist:7607264
Last active December 29, 2015 03:19
Automatic Model Binding between Unregistered Ember Views and Controllers

Normally, if you register views and controllers (with the same name), when they're instantiated, Ember automatically wires them up to each other. view.controller points to the controller you'd expect and both view.content and controller.model are bound to each other. If one changes, so does the other.

However, registering everything with the App means your App namespace gets very polluted, and you have to be very careful choosing your names so you don't collide with views/controllers being defined/used elsewhere in the App. Also, sometimes you have a view/controller that you're only using in one very specific place and it's just kinda silly to have it registered and accessible at a "global" level. In these cases, it's logical to NOT register your views/controllers, but that means things don't get magically wired up by Ember and things don't work the way you'd normally expect.

If you don't register your view/controller, then when you try {{view MyUnregisteredView contentBinding="myModel"}}, you get a