Skip to content

Instantly share code, notes, and snippets.

View dougalcorn's full-sized avatar

Doug Alcorn dougalcorn

View GitHub Profile
@dougalcorn
dougalcorn / Order.rb
Last active October 1, 2020 21:21
Order processing from the database based on status
class Order
def self.ready_to_queue
where(status: new_states)
end
def self.new_states
['created', '', nil]
end
@dougalcorn
dougalcorn / README.md
Created October 30, 2018 15:37
Resetting Primary Key Sequence in Rails

I exported a table worth of data from one postgres instance as CSV and then directly imported into another postgres instance bypassing rails using the \copy command like so:

\copy my_table to ‘my_table.csv’ csv;

and

\copy my_table from ‘my_table.csv’ with (format csv);
@dougalcorn
dougalcorn / ejabberd.cfg
Created July 18, 2013 13:33
Problems with registering my first user from the command line on ejabberd on ubuntu
{hosts, ["localhost", "semperubisububi.org"]}.
{access, max_user_sessions, [{10, all}]}.
{access, max_user_offline_messages, [{5000, admin}, {100, all}]}.
{access, local, [{allow, all}]}.
{access, c2s, [{deny, blocked},
{allow, all}]}.
{access, c2s_shaper, [{none, admin},
{normal, all}]}.
{access, s2s_shaper, [{fast, all}]}.
@dougalcorn
dougalcorn / README.md
Created February 8, 2018 15:49
Simple way to mount react components

This is a fairly simply way to bootstrap react components into server side rendered pages.

The server template has a div with data-component attribute who's value is the name of the component you want mounted. Each of the other data attributes are turned into properties for the component. It assumes the format is data-some-property-name and it's converted into a somePropertyName property.

For this to work, the component has to imported and assigned onto the global window namespace. The mountReactComponent function does an eval of the data-component name in order to create the React component.

If anything, this is the biggest weakness of this strategy. It requires poluting the global namespace with any of your top-level react components and also does a JS eval of strings from the markup. This could potentially be dangerous.

@dougalcorn
dougalcorn / locateble.rb
Created December 23, 2010 18:03
Basic ruby blass with parts of an address that can be assembled into a string and geolocated with Google Maps api
GOOGLE_MAPS_API_KEY = "something"
# This is a plain old ruby class that assumes someone has give it the
# parts of an address. The end goal is to use Google to geolocate it
# and assign a lat/long
class Locateable
attr_accessor :street1, :street2, :city, :state, :country
attr_accessor :latitude, :longitude, :accuracy
# returns false if google was unable to geolocate the
@dougalcorn
dougalcorn / open_ports.md
Last active March 14, 2016 13:46
Some questions about ports "open to the world"

@p9k put out a question on Twitter about ports open to the world: https://twitter.com/p9k/status/408721475345330177

$ netstat -na|grep '^tcp4\W.*\*\.\d.*LISTEN'|wc -l
       5

His command was specifically only looking for processes listening on an IPv4 TCP port. I've modified the filter to pull both IPv4 and IPv6 TCP ports.

Web Development with Ruby on Rails and Nitrous.IO.

Introduction

We will create a simple "Wish List" Web application using Ruby on Rails (Rails) and Nitrous.IO (Nitrous).

Rails is a Web application development framework written in the Ruby programming language. It follows a "convention over configuration" philosophy that allows developers to quickly create valuable products if they choose to follow convention. However, Rails is powerful enough to to create applications like Twitter and Groupon.

Nitrous is a Web-based application development service. It permits software developers to focus on writing code and less on the intricacies of their development environment. Their tagline is, "making coding in the cloud a reality." Using Nitrous, you are literally programming a server running in "The Cloud."

@dougalcorn
dougalcorn / failure_message.txt
Created December 10, 2011 15:36
Simplified example of failing any_in criteria for mongoid using string id fields
Failures:
1) Mongoid inclusion criteria
Failure/Error: @criteria.selector.should == {"$in" => {:from_id => [from_port.id, to_port.id]}}
expected: {"$in"=>{:from_id=>["6055df90-0572-012f-2043-388d1201202c", "60562bc0-0572-012f-2043-388d1201202c"]}},
got: {:from_id=>"{\"$in\"=>[\"6055df90-0572-012f-2043-388d1201202c\", \"60562bc0-0572-012f-2043-388d1201202c\"]}"} (using ==)
Diff:
@@ -1,5 +1,3 @@
-{"$in"=>
- {:from_id=>
@dougalcorn
dougalcorn / irb
Created December 9, 2011 22:01
$in criteria in Mongoid
irb(main):062:0> base.in(:from_id => port_ids)
=> #<Mongoid::Criteria
selector: {:from_id=>"$in0d06b030-04d8-012f-18e7-388d1201202c5b932da1-04d8-012f-b944-388d1201202c"},
options: {},
class: Ccom::PortConnection,
embedded: false>
# that's a jacked up selector
# now not using the _id on the field name
@dougalcorn
dougalcorn / gist:1242310
Created September 26, 2011 14:05
Bash Prompt for Git Status
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
# Black 0;30 Dark Gray 1;30
# Blue 0;34 Light Blue 1;34
# Green 0;32 Light Green 1;32