Skip to content

Instantly share code, notes, and snippets.

Nick Hoffman nickhoffman

Block or report user

Report or block nickhoffman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nickhoffman
nickhoffman / run.rb
Last active Apr 15, 2016
Code Kata: string splitter
View run.rb
class String
def multiline_split(max_line_length)
self
end
end
puts "foo\nbar\nbaz" == "foo bar baz".multiline_split(3)
puts "foo bar\nbaz" == "foo bar baz".multiline_split(9)
View gist:579623b5d1f98a621cd8
Chart
http://www.cpubenchmark.net/high_end_cpus.html
http://products.amd.com/en-us/DesktopCPUResult.aspx
http://ark.intel.com/
http://ark.intel.com/compare/80814,80809,80808,80806,80807
http://processors.findthebest.com/d/n/AMD
View Configure IRB's prompt for a Rails app
if defined? Rails
# Customize the IRB prompt.
short_env = case Rails.env
when 'development'
'dev'
when 'production'
'prod'
else
Rails.env
@nickhoffman
nickhoffman / gist:3015881
Created Jun 29, 2012
ElasticSearch: Parent/Child: Find children based on parent properties
View gist:3015881
#!/bin/bash
# Reset the index.
curl -X DELETE "localhost:9200/test/?pretty=true"
curl -X PUT "localhost:9200/test/?pretty=true"
# Create the parent mapping.
echo
curl -X PUT "localhost:9200/test/user/_mapping?pretty=true" -d '{
"user": {
View true_false_comparison.rb
module TrueFalseComparison
# Enable TrueClass and FalseClass values to be comparable.
# TrueClass values are valued higher than FalseClass values.
#
# See this article for more info:
# http://grosser.it/2010/07/30/ruby-true-false-comparison-with/
#
# Yes, this is evil monkey-patching. The alternative is much, much worse:
#
# [false, true, false].sort {|a, b| a ? (b ? 0 : -1) : (b ? 1 : 0) }
View output.txt
The first context
Creating Person with name Nick
✗ Errored » callback not fired
in Create a Person via JavaScript: When a person has a name,
in Creating a Person
in undefined✗ Errored » 1 errored ∙ 1 dropped
@nickhoffman
nickhoffman / gist:2481672
Created Apr 24, 2012
MySQL's "REPEATABLE READ" and "SELECT ... FOR UPDATE"
View gist:2481672
mysql> show create table numbers\G
*************************** 1. row ***************************
Table: numbers
Create Table: CREATE TABLE `numbers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`num` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
@nickhoffman
nickhoffman / gist:1666614
Created Jan 24, 2012
Nesting text within a content tag.
View gist:1666614
# The HTML that should be generated is:
# <h3 class="curated_by">Curated by <span>Bob</span></h3>
# Please tell me that there's a better way to do this.
def curated_by
html = ''
html += h.content_tag(:h3, :class => 'curated_by') do
h.concat h.t('phrases.Curated_by')
h.concat ' '
View query_with_exclamation.sh
curl 'localhost:9200/development_products/product/_search?pretty=true' -d '
{
"query" : {
"dis_max" : {
"queries" : [
{ "field" : {"name" : "Arise!"}},
{ "field" : {"catalog.name" : "Arise!"}}
]
}
}
@nickhoffman
nickhoffman / option_1.rb
Created Jan 13, 2012
Would you duplicate the validation's regex, or reference a constant?
View option_1.rb
class User
field :username, :type => String
validates :username, :format => { :with => /\A[[:print:] ]{3,20}\Z/ }
end
class ScoreCard
belongs_to :user
field :username, :type => String
You can’t perform that action at this time.