Skip to content

Instantly share code, notes, and snippets.

View pagebrooks's full-sized avatar
👽

Page Brooks pagebrooks

👽
View GitHub Profile
@pagebrooks
pagebrooks / usa_state_hash.rb
Created October 26, 2011 19:15 — forked from sdball/usa_state_hash.rb
United States State Abbreviation Hash
@states = {
AL: "Alabama",
AK: "Alaska",
AZ: "Arizona",
AR: "Arkansas",
CA: "California",
CO: "Colorado",
CT: "Connecticut",
DE: "Delaware",
FL: "Florida",
@pagebrooks
pagebrooks / FormatWith.cs
Last active September 28, 2015 18:18
FormatWith Extension Method
[DebuggerStepThrough]
public static string FormatWith(this string target, params object[] args)
{
if (string.IsNullOrEmpty(target))
{
return string.Empty;
}
return string.Format(CultureInfo.CurrentCulture, target, args);
}
@pagebrooks
pagebrooks / JsonNetResult.cs
Created December 7, 2012 00:28
Angular Compatible Date Formatting with JSON.NET
public class JsonNetResult : JsonResult
{
private readonly static JsonSerializerSettings Settings;
private readonly static IsoDateTimeConverter _dateTimeConverter;
static JsonNetResult()
{
_dateTimeConverter = new IsoDateTimeConverter();
// Default for IsoDateTimeConverter is yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK
_dateTimeConverter.DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFK";
@pagebrooks
pagebrooks / ToSelectList.cs
Created December 7, 2012 00:50
ASP.NET MVC Html Helper for generating a select list from a dictionary
public static List<SelectListItem> ToSelectList(this Dictionary<string, string> items, string defaultItem, bool insertBlankItem = false)
{
string[] defaultItems = new[] { defaultItem };
if (!string.IsNullOrWhiteSpace(defaultItem))
{
defaultItems = defaultItem.Split(',');
}
var i = items.Select(pair => new SelectListItem
{
@pagebrooks
pagebrooks / couchdb-install
Last active December 13, 2015 17:18
I guide for installing CouchDB 1.2.1 on Ubuntu 12.04
Resources
http://onabai.wordpress.com/2012/05/10/installing-couchdb-1-2-in-ubuntu-12-04/
http://depth-first.com/articles/2010/01/28/pubcouch-install-couchdb-on-ubuntu-karmic-from-source/
http://wiki.apache.org/couchdb/Installing_on_Ubuntu
http://guide.couchdb.org/draft/source.html
http://grokbase.com/t/couchdb/user/114m97mzd0/installations-problem-with-couchdb
http://cvee.github.com/blog/2011/11/28/configuring-couchdb-on-ubuntu/

Procedure for upgrading a standalone MongoDB

  • Upgrade applications to use the latest Mongo Driver and then test applications to make sure they work using the latest version of driver with old database version.

  • Shutdown Mongod: > db.shutdownServer()

  • Verify that the service actually stopped using: $ sudo service mongodb status

  • Create a backup copy of all databases $ sudo cp –vrp /media/data/mongodb /media/data/mongodb-backup

Procedure for Mongodb Logrotate

The default install for Mongodb does not configure log rotation.

In /etc/logrotate.d/mongod

/var/log/mongodb/*.log {
    daily
    rotate 30
    compress

dateext

@pagebrooks
pagebrooks / WatiNHelper.cs
Last active June 26, 2017 07:53
This helper class adds Eval so that you can obtain the result of a JavaScript function. This functionality is not native to WatiN. Forked from: http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin
// Forked from: http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin/
// This helper class adds Eval so that you can obtain the result of a JavaScript
// function. This functionality is not native to WatiN.
/*
* Usage:
* var browser = new IE();
* var foo = browser.NativeDocument.Eval<bool>("isFoo()");
*/
@pagebrooks
pagebrooks / sed-replace.sh
Last active December 23, 2015 03:59
sed one-liner that will inject value into configuration file.
# Find a string that starts with bind-address= and replace anything after the = with 0.0.0.0
# For example, in the my.cnf file, this would replace:
# bind-address = 127.0.0.1
# with
# bind-address = 0.0.0.0
sed -i 's/^\(bind\-address\s*=\s*\).*$/\10\.0\.0\.0/' /etc/mysql/my.cnf
<select id="state" name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>