Developer Blog — 2018.08.29

tdre(65)
Published in
#blog
Words
521
Reading
3 min
Listen
Play
8y

Here's your chance to steal two or three incantations from my spell book. It's only fair. I'm sure I stole them from somewhere first.

"Good coders copy, great coders steal. But the best steal and cut you in." — Anonymous

blog-header.png

A CSP compliant alternative to Knockout's default bindings

I worked on some improvements to Anole this week, in effort to add enough features for a presentable launch worth some fanfare. In doing so I came across an interesting speed bump concerning frameworks in extension development.

When developing a Chrome extension the easiest way to use Knockout.js is with a custom binding provider. The browser's Content Security Policy ordinarily prevents Knockout from accessing the less secure eval and new function statements. However, with an alternative binding provider, these need not be relied upon..

I was fortunate twice when I hit this snag. Firstly because the same day by coincidence I had read about Content Security Policy's lockout of eval and new function — so I was able to recognize the obstacle fairly quickly.

The idea of writing a secure binding was one I had in mind already when good fortune struck again. An open source solution already existed on GitHub, thanks to brianmhunt.

Visual Studio snippets every C# coder should know

While I've long been a handy user of code completion I only recently started relying on code snippets in Video Studio to cut down on typing. It's a tip I picked up while reviewing Scott Allen's C# Fundamentals course on Pluralisght as an old dog in search of new tricks.

For C# In VS you type a snippet identifier followed by TAB twice to activate a snippet. There are several essentials built in for C#. It is not too hard to define your own. I am currently working to create a set of custom snippets to share in an upcoming post. Until then here are the core must haves:

For organizing code
  • class to create a new class
  • ctor to create a new constructor
  • prop to create a property declaration with auto-implemented getter and setter
  • try to create a try-catch block and tryf to create a try-catch-finally
For logic and flow
  • do to make a do-while loop and while for a simple while loop
  • if to create an if block and else to create an else block. Note — I find it's much better to make a custom ife snippet so you can simply make the if-else block in one fell swoop.
  • switch to create a switch block
For console apps
  • cw to call WriteLine().
  • svm to declare a static void Main() method

Git & shell aliases

Finally, in celebration of having finally stumbled upon the perfect command line shortcut to keep my local git repos uncluttered with stale branches I would like to share with you the set of aliases that I'm currently using to save time in git.

This set grew and contracted over time until I finally settled on a small set that I actually use on a daily basis.

alias mint='git branch | grep -v "master" | xargs git branch -D'

The above quick pruning of non-master branches — which I call mint, for some reason — was for me the last missing ingredient in the next.

These are also available as this gist.

For bash
alias ls='ls --color=auto -F'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias less="less -R "

alias mint='git branch | grep -v "master" | xargs git branch -D'

alias php="php -c ~/workspace/php.ini"
alias ..="cd .."

alias hott="prettier --write --single-quote \"{,!(node_modules)/**/}*.js\""
alias newex="express --git --view pug"
alias dpak="npm i -D babel-core babel-preset-env babelify browserify uglify-js"
alias bump="npm --no-git-tag version"
For git

in .gitconfig

. . .

[alias]
  co = checkout
  ci = commit
  cip = commit -p
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  fit = cat-file -t
  fip = cat-file -p    
  fa = fetch --all
  pa = pull --all
  mn = merge --no-ff

. . .

Developer Blog — 2018.08.29 | Ecency