dotfiles backup using GitHub
I was recently looking for a solution to backup my configuration files (bash, vim, etc) using GitHub. After some looking around, I've compiled a pretty nice project for myself.
First, this script checks dependencies. My dependencies are git, ruby, vim, tree, rake, gem, bundle, and trash. You could check out the code and add any number of dependencies here. Rubygems and bundler are required because the script later installs all gems listed in Gemfile.
Next, the script copies ~/.bashrc to ~/.bashrc.local. This allows you to keep your current bash configuration as a 'local-only' config that doesn't get copied or committed to github.
The script, as I copied most of bootstrap.sh and the rakefile from @gf3, expects the repository to be cloned to ~/.dotfiles. From there, it calls rake.
Rake looks at every file in ~/.dotfiles and copies the corresponding file relatively from ~/ to, essentially, ~/dotfiles-backup/`date`. I recommend first running the backup to make sure your files are properly backed up.
rake backup
The script then calls 'bundle install' to install all gems. It then copies all files from ~/.dotfiles to replace those relative files that were previously backed up from ~/.
The post-install displays a message to remind you to edit .gitconfig and .hgrc.
Because I've done some copying and compiling, these are relative close to the three projects in the README for right now.
Here is an excerpt from the README:
Bash
$ tree ~/.bash
/home/jim/.bash
├── aliases
├── completions
├── completion_scripts
│ └── git_completion
├── config
├── functions
├── paths
└── prompt
The above files are loaded by .bashrc. The files are pretty self-explanatory, other than prompt which colorizes the bash prompt with tweaks for git.
Cool Aliases
- cd : pushd
- bd : popd
- cd.. | .. : back one directory
- cd... | ... : back two directories
- ^ up to five directories
- rm : trash
- undopush
- ip
- GET | HEAD | POST | PUT | DELETE | TRACE | OPTIONS
Config
- sets editor to vim
- sets English/UTF-8
- sets manpager
- sets commands to ignore in history
- sets noclobber (e.g. prevents
cat > IMPORTANT_FILEmistakes ) - sets nocaseglob (e.g.
ls ~/.B*will list contents of~/.bash)
Functions
The two functions, md and c may not seem like much, but they simplify some commands. For example:
$ md projects; git clone git@github.com:jimschubert/dotfiles.git && cd dotfiles
In the above line, md will create the projects directory and cd into it.
c stands for 'code' and works like this:
jim at computer in ~
$ pwd
/home/jim
jim at computer in ~
$ c dotfiles
~/projects/dotfiles ~
jim at computer in ~/projects/dotfiles on master
$
You can change it to whatever shortcut and issue reload, which is also an alias from this setup.
Screenshot
Notice the color scheme and github branch notifications created by ~/.bash/prompt.
Install nodejs under ChromeOS (CR-48)
Why would I want to do this?
I'm a software developer. I love javascript. I love node.js. I love the direction Google is taking web development, user interaction, and the web in general. Installing node.js opens up a lot of possibilities for me on my CR-48. I don't know if this will work on anything other than the CR-48, considering the machine has to be in developer mode for these instructions.
If you don't have a chromebook yet, or you don't know what they are... where have you been? But seriously, visit http://www.google.com/chromebook/ and check them out.
Before I start, let me first say that following these instructions may void your warranty if you have one, open your machine up to vulnerabilities, or replace existing files and cause instability. If you don't know how to revert or fix any issues that may occur, don't continue. I offer no sort of warranty, support, or anything else. Consider this a 'hack' of sorts.
I found a blog post detailing how to install an archive package and ruby on rails in ChromeOS. I followed part of these instructions and I have modified them to fit my needs.
Prerequisites
- You must have a Chromebook, possibly only the CR-48
- You must be in 'developer mode'
- You must have a writable rootfs (see above link for developer mode)
Instructions
Downloading and installing xz
- Download the xz package
- Enter crosh or VT-2 (CTRL+ALT+T or CTRL+ALT+→)
- If VT-2, login to the shell
- Run on the terminal: cd /home/chronos/user/Downloads
- Run on the terminal: tar -zxf xz-*.tar.gz
- Run on the terminal: cd usr
- Run on the terminal: cp * /usr/
Now that xz is installed in /usr/bin (verify by running on the command line: which xz), you will be able to extract certain files that are necessary for nodejs and possibly any other package you'd like.
Download and install nodejs and openssl.
The site claims openssl is optional, but node wouldn't open without it
- Download nodejs
- Download openssl
- Enter the terminal again and navigate to /home/chronos/user/Downloads
- Run on the terminal: xz -d node*.xz
- Run on the terminal: tar -zxfv openssl*.tar.gz
- Run on the terminal: cd usr
- Run on the terminal: cp * /usr/
Now you should have a working install of nodejs. You can use npm, for instance, to install express and jade.

Visual Studio and Interface property stubs
Last year, I posted a question on StackOverflow asking if it was possible to replace the property stubs for interface refactoring
Is it possible to change the stub used to implement interfaces in Visual Studio 2008?
For instance, when I choose either
Implement interface 'IMyInterface'
or
Explicitly implement interface 'IMyInterface'
Instead of a number of properties that look like this:
public string Comment
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
I'd like my properties to use the C# 3.0 auto-implemented properties and look like this:
public string Comment {get;set;}
I want to do this to avoid forcing this interface to be an abstract class.
I've looked through the snippets in the Visual Studio folder, but I didn't see any that would be appropriate. I've also googled and searched SO, and found nothing.
If this isn't possible, does anyone have a macro I can steal?
Thanks.
I then discovered that you can edit the file at:
[program files]\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring\PropertyStub.snippet
and modify the xml node 'Code' to contain the following:
<Code Language="csharp">
<![CDATA[ $signature$ { $GetterAccessibility$ get; $SetterAccessibility$ set;} $end$]]>
</Code>
I really wish this was the default for .NET 3.0 and higher (since auto-implemented properties have been around).
My Review of JavaScript: The Definitive Guide, 6th Edition
A tome of knowledge
Pros: Well-written, Accurate, Concise, Easy to understand
Cons: Huge
Best Uses: Student, Expert, Novice, Intermediate
Describe Yourself: Developer
This is an unbelievably thorough JavaScript book. It's definitely more of a reference book than a front-to-back read.
The first 12 chapters are an excellent introduction into the history of JavaScript and the core functionality of the language. There is a lot of information in these chapters that really shouldn't be overlooked-- especially Chapter 8: "Functions".
I especially appreciate the structure and the approach of the client-side section of the book. Flanagan makes it a point to avoid pushing JavaScript frameworks by explaining the features of the language first, followed by an explanation of the cross-browser simplification of using jQuery.
Later chapters cover additions to more recent browsers like client storage and HTML5 features. Those chapters unfortunately go by really fast. They're definitely not as in-depth as the JavaScript history part of the book.
The last two parts of the book are purely reference. This is pretty helpful, but it makes the book a lot thicker than most "guide" references.
I do agree with others that this book could use a few more examples, especially near the end when discussing JavaScript usage with new HTML5 APIs. If you're looking for an in-depth understanding of the core functionality of JavaScript, this is the book. It has helped me in numerous job interviews!
(legalese)
jQuery plugin: fixed table header
Here's a plugin that I wrote a while ago for fixing a table's header row on scroll.
This code is also available as a gist. Fork it and contribute.
(function($) {
$.fn.fixedHeader = function(options) {
var settings = {
selector: 'thead:first',
cssClass: 'fixed',
fixTo: 0
};
var _fixHeader = function(obj) {
var header = $(obj.selector, obj.elem);
if(header) {
var parent = header.parents('table:first') || header.parent();
(parent && parent.css({ borderCollapse: 'collapse'}) );
var data = header.data('fixedHeader') || header.data('fixedHeader', {
top: header.offset().top,
width: parent.find('tr:eq(1)').width(),
cells: parent.find('tr:eq(1) > td'),
processed: false
});
var top = data.top - $(document).scrollTop();
if( top < 0 ) {
header.addClass(obj.css);
if(!data.processed){
header.width(data.width);
for(var i = 0; i<data.cells.length;i++) {
$('th:eq('+i+')', header).width($(data.cells[i]).width());
}
}
} else {
header.removeClass(obj.css);
}
}
};
return this.each(function() {
var self = this;
if("object" === typeof options) {
$.extend(settings, options);
}
if($(self).parents('table:first')){
$(window).bind('scroll.fixedHeader', function() {
_fixHeader({
elem: self,
selector: settings.selector,
css: settings.cssClass,
top: settings.fixTo
});
});
}
});
};
})(jQuery);
A demo:
Mercurial and Git in one repository
I have a personal project hosted at bitbucket using Mercurial as the version control system. Since I started that project, I've been using GitHub for everything. I just found hg-git instructions on github.com. It is pretty awesome.
For my purposes, it allows me to maintain the project on two remote servers, one running Mercurial, the other running Git.
To see how it works, first install hg-git:
$ sudo easy_install hg-git
Then, edit your ~/.hgrc settings, adding to the [extensions] section:
[extensions] hgext.bookmarks = hggit =
Also, be sure your ~/.hgrc contains a valid email address:
[ui] username = Jim Schubert <james.schubert@gmail.com>
Now, you can create a repository on github.com and push your Mercurial commits:
$ cd ~/projects/project_name $ hg bookmark -r default master $ hg push git+ssh://git@github.com/username/project_name.git $ hg push
If you're only planning on using Mercurial to push changes to github or some other Git host, you can add that path to ~/.hgrc:
[paths] default-push = git+ssh://git@github.com/username/project_name.git
Makefile setup for minifying .js files in an expressjs application
There's not really any reason to uglify or minify your JavaScript files on a per-request basis or on a pre-cache basis. This should be done at deployment time only. This can be achieved by adding uglify-js to your package.json file.
// default package.js for an expressjs app using ejs and uglify-js
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.4.6"
, "ejs": ">=0.4.3"
, "uglify-js": ">=1.1.0"
}
}
Make sure the dependencies are installed with
npm install -d
Then, add the following make file and minify your JavaScripts as part of your make process!
JS = $(shell find public/javascripts/*.js) MINIFY = $(JS:.js=.min.js) all: clean $(MINIFY) clean: rm -f ./public/javascripts/*.min.js %.min.js: %.js node ./node_modules/uglify-js/bin/uglifyjs -o $@ $< .PHONY: clean js minify
(expandable source is the same as the gist. It is doubled here to show in RSS feed readers.)
propv.snippet for creating Automatic virtual properties in C#
I'm all about saving time. I have a huge collection of helpful snippets. Here's one that automatically creates a virtual property, which is really helpful if you use Castle's DynamicProxy (NHibernate uses this).
Instead of embedding the code directly, I'm using http://gist.github.com so changes to the file will show immediately in the post.
Editing JavaScript in vim
I primarily use vim as my editor of choice for JavaScript.
I have a fairly simple .vimrc:
syntax on " enabled syntax highlighting :set number " line numbers :set ai " autoindent :set tabstop=4 " sets tabs to 4 characters :set shiftwidth=4 :set expandtab :set softtabstop=4 " makes the spaces feel like real tabs " CSS (tabs = 2, lines = 79) autocmd FileType css set omnifunc=csscomplete#CompleteCSS autocmd FileType css set sw=2 autocmd FileType css set ts=2 autocmd FileType css set sts=2 " JavaScript (tabs = 4, lines = 79) autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType javascript set sw=4 autocmd FileType javascript set ts=4 autocmd FileType javascript set sts=4 " autocmd FileType javascript set tw=79 autocmd FileType jade set omnifunc=jadecomplete#CompleteJade autocmd FileType jade set sw=2 autocmd FileType jade set ts=2 autocmd FileType jade set sts=2 " Highlight current line only in insert mode autocmd InsertLeave * set nocursorline autocmd InsertEnter * set cursorline " Makefiles require TAB instead of whitespace autocmd FileType make setlocal noexpandtab " Highlight cursor highlight CursorLine ctermbg=8 cterm=NONE
I also use the JavaScript syntax/indents found here:
https://github.com/pangloss/vim-javascript
You can access the completion by typing CTRL+X,CTRL+O.
If you have any other suggestions for using vim as a JavaScript editor, let me know!
testy C# Test Method Snippet
This is a pretty trivial snippet, but I use it quite a lot.
Save this file as testy.snippet in your [Visual Studio]\VC#\Snippets\1033\Test directory.
Then, in the code editor, type testy, TAB+TAB to expand the snippet.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>testy</Title>
<Shortcut>testy</Shortcut>
<Description>Code snippet for creating an NUnit unit test in C#</Description>
<Author>James Schubert</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>summary</ID>
<ToolTip>Summary</ToolTip>
<Default>Summary</Default>
</Literal>
<Literal>
<ID>name</ID>
<ToolTip>Test name</ToolTip>
<Default>TestName</Default>
</Literal>
<Literal>
<ID>description</ID>
<ToolTip>Test Case</ToolTip>
<Default>Assumption_Does_Expectation</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[ ///<summary>
/// $summary$
///</summary>
[Test]
public void $name$_When_$description$()
{
// Arrange
// Act
// Assert
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

