Developer Blog — 2018.08.29

in #blog6 years ago (edited)

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

. . .

Sort:  

This contribution was a bit more technical than what we're used to seeing in the Blog category, but that's definitely not a knock on it. It certainly seems like a valuable update. However, there are some issues with it.

First, is the fact that while parts of the C# library are open source, not all of it is. And Visual Studio is essentially closed source, despite having some open-source plugins. So while your solution itself is open source, the software being used is not entirely in our categories.

Another content issue is that this post relies very heavily on existing knowledge on the part of the reader. As I wrote, being technical is not a knock, but it's good to make the content more accessible to a general reading public. Explaining what Anole is, for instance, would have been good. And also a positive for you, as the extension's developer.

While the post is generally quite well written, there are also issues of style and proofreading. I'll cite a couple of examples:

  • "However with an alternative binding provider these need not be relied upon" really needed a couple of commas. It would be easier to read as: "However, with an alternative binding provider, these need not be relied upon."

  • "While I've long been a handy user of code completion for some while" is redundant, and looks to be the result of a sentence what was partially edited. You don't need both "long been" and "for some while."

Greater focus on proofreading could have really elevated this post, to my mind.

Thank you for your contribution.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks @didic for taking the time moderate and offer feedback. I agree with your remarks and have made the suggested revisions. While it's no excuse, those groaners that I didn't catch do illustrate some consequences of proofreading sleepy ;)

Again, your thoughtful response was much appreciated.

Thank you for your review, @didic!

So far this week you've reviewed 2 contributions. Keep up the good work!

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by tdre from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Hi @tdre! We are @steem-ua, a new Steem dApp, using UserAuthority for algorithmic post curation! Your post is eligible for our upvote, thanks to our collaboration with @utopian-io! Thanks for your contribution, keep up the good work, and feel free to join our @steem-ua Discord server

Hey, @tdre!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!