Skip to content

Instantly share code, notes, and snippets.

View thephw's full-sized avatar
❤️
Building software with love

Patrick Howard Wiseman thephw

❤️
Building software with love
View GitHub Profile
@thephw
thephw / logger.coffee
Last active December 16, 2015 03:59
A super easy logger wrapper for making dumb js frameworks less dumb. By all means steal this. Please.
root = exports ? this
root.Logger =
class Logger
constructor: (options = {}) ->
@mapping = options.mapping ? {
error: (message) ->
console.error.call console, message
warn: (message) ->
console.warn.call console, message
info: (message) ->
@thephw
thephw / es.sh
Last active December 17, 2015 13:49 — forked from rajraj/es.sh
Install elasticsearch on Amazon linux AMI.
cd ~
sudo yum update
sudo yum install java-1.7.0-openjdk.i686 -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.0.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/share
@thephw
thephw / model_snippet.rb
Created November 8, 2013 16:40
My weird way of not rewriting all of the json for to_json and to_indexed_json
# ...
# Helper Function
def index_content
require 'open-uri'
if self.content.present? && self.content.url.present? && self.content.url.downcase.ends_with?("pdf")
uri = URI.join HOSTNAME, self.content.url
io = open(uri)
reader = PDF::Reader.new(io)
reader.pages.collect(&:text).join
end
@thephw
thephw / mens_roller_derby.geojson
Last active December 29, 2015 01:49
Men's Roller Derby Teams
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thephw
thephw / one_line_ruby_server.rb
Created December 9, 2013 14:13
One line ruby server
ruby -run -e httpd . -p5000
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thephw
thephw / css_color.rb
Created February 7, 2014 19:19
A quick color helper for getting other CSS color types to RGBA, it copies it to your clipboard
########################
## Ruby color helpers ##
########################
require 'clipboard'
def css_color(text, output_type = "rgba")
if text.start_with? "#"
if text.length > 4
colors = [text[1..2].to_i(16).to_s(10), text[3..4].to_i(16).to_s(10), text[5..6].to_i(16).to_s(10), 1]
else
colors = [(text[1]*2).to_i(16).to_s(10), (text[2]*2).to_i(16).to_s(10), (text[3]*2).to_i(16).to_s(10), 1]
public static FieldViewModel GetField(this HtmlHelper<IEnumerable<FieldViewModel>> Html, string fieldId)
{
FieldViewModel field = Html.ViewData.Model.SingleOrDefault(f => f.FieldId == fieldId);
return field;
}
SELECT creation_time
,last_execution_time
,total_physical_reads
,total_logical_reads
,total_logical_writes
, execution_count
, total_worker_time
, total_elapsed_time
, total_elapsed_time / execution_count avg_elapsed_time
,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
private static MembershipContext _dbContext;
public static MembershipContext dbcontext
{
get
{
if (_dbcontext==null)
{
_dbcontext = new MembershipContext();
}
return _dbcontext;