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
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
classto create a new classctorto create a new constructorpropto create a property declaration with auto-implemented getter and settertryto create atry-catchblock andtryfto create atry-catch-finally
For logic and flow
doto make ado-whileloop andwhilefor a simplewhileloopifto create anifblock andelseto create anelseblock. Note — I find it's much better to make a customifesnippet so you can simply make theif-elseblock in one fell swoop.switchto create a switch block
For console apps
cwto callWriteLine().svmto declare astatic 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
. . .