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 / 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 / README.md
Last active August 29, 2015 14:05
rspec contexts

The lets are evaluated from inner-most to outer; but the before are evaluated from outer to inner. With rspec-given the point is to use When as just the bit of code that's "under test". All of the Givens are pre-conditions or setup. That's one of the things I like most about rspec-given, it separates setup code from code under test. The other thing I like about it is the brevity of the individual tests. I find the description on it blocks often quite redundant with the code in the block. I like how Then removes that duplication. Another benefit of rspec-given is that is has natural language failures built in. That's pretty cool.

@dougalcorn
dougalcorn / gist:11060606
Created April 18, 2014 19:29
Infuriating error
$ brew update libyaml
This command updates brew itself, and does not take formula names.
Use `brew upgrade <formula>`.

Keybase proof

I hereby claim:

  • I am dougalcorn on github.
  • I am dougalcorn (https://keybase.io/dougalcorn) on keybase.
  • I have a public key whose fingerprint is 4AFA 9F41 2256 E31E B97F 86AA 7EBC 2B80 3393 094A

To claim this, I am signing this object:

@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 / 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 / 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=>