Skip to content

Instantly share code, notes, and snippets.

I, [2014-09-16T13:53:52.616946 #17989] INFO -- : SOAP request: http://127.0.0.1:8080/index.php/api/v2_soap/index/
I, [2014-09-16T13:53:52.617093 #17989] INFO -- : SOAPAction: "urn:Mage_Api_Model_Server_V2_HandlerAction", Content-Type: text/xml;charset=UTF-8, Content-Length: 583
D, [2014-09-16T13:53:52.617162 #17989] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typens="urn:Magento" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><typens:shoppingCartCustomerSet><sessionId>f64157706ed396c47e3ed0c461498c30</sessionId><quoteId>2</quoteId><customerData><firstname>testFirstname</firstname><lastname>testLastName</lastname><email>testEmail@mail.com</email><mode>guest</mode><website_id>0</website_id></customerData></typens:shoppingCartCustomerSet></env:Body></env:Envelope>
D, [2014-09-16T13:53:52.617332 #17989] DEBUG -- : HTTPI POST request to 127.0.0.1 (net_http)
I, [2014-09-16
@davetapley
davetapley / regex.rb
Created August 18, 2014 23:25
\a \A \z \Z in Ruby regexes
irb(main):001:0> 'derp' =~ /derp\Z/
=> 0
irb(main):002:0> 'derp' =~ /derp\z/
=> 0
irb(main):003:0> 'derp' =~ /\Aderp\z/
=> 0
irb(main):004:0> 'derp' =~ /\aderp\z/
=> nil
@davetapley
davetapley / sequel_pk_in_module.rb
Created July 22, 2014 04:38
Explicitly declaring Sequel PK in module
def self.included(o)
o.extend ClassMethods
o.set_primary_key [:user_id, :period]
o.unrestrict_primary_key
end
@davetapley
davetapley / indexes.sql
Created July 22, 2014 03:46
Implicit primary key index is redundant
"events_pkey" PRIMARY KEY, btree (user_id, period)
"events_user_id_period_excl" EXCLUDE USING gist (user_id WITH =, period WITH &&)
@davetapley
davetapley / pg.sql
Last active August 29, 2015 14:03
Postgres range empty check, with inclusive/exclusive end bound
test=# SELECT isempty('[0,0]' :: int4range);
isempty
---------
f
(1 row)
test=# SELECT isempty('[0,0)' :: int4range);
isempty
---------
t
@davetapley
davetapley / considating_ranges.md
Last active August 29, 2015 14:02
Consolidating ranges across a union in Postgresql

Two tables share a user_id, a tstzrange called period, then each have another column called category and place_id respectively. Both have constraints allowing a user to only have one 'other column' value at any time:

 user_id    | integer                  | not null
 period     | tstzrange                | not null
 category   | character varying(16)    |

    "category_events_user_id_period_excl" EXCLUDE USING gist (user_id WITH =, period WITH &&)
@davetapley
davetapley / clustering.txt
Last active August 29, 2015 14:02
Clustering
Start with a list of clusters:
a, b, x, c, x, x, d, e, f, g, x, h
Select out clusters to try and find a place for:
a, b, c, d, e, f, g, h
Map over a method to (optionally) assign a place (pN) to each cluster:
(this is done with a DelegateClass containing the place or nil)
@davetapley
davetapley / array_iter.rb
Created June 12, 2014 18:00
Array Iter in Ruby
class ArrayIter < Array
class Iter < SimpleDelegator
attr_reader :next
attr_reader :prev
end
def <<(other)
last.instance_variable_set(:@next, other) if last
other_iter = Iter.new other
test=# CREATE TABLE tzs(with_tz TIMESTAMP WITH TIME ZONE, without_tz TIMESTAMP WITHOUT TIME ZONE, comment TEXT);
CREATE TABLE
test=# INSERT INTO tzs VALUES( now(), now(), 'now()');
test=# INSERT INTO tzs VALUES( timezone('America/New_York', now()), timezone('America/New_York', now()), 'timezone(New York, now())');
INSERT 0 1
test=# INSERT INTO tzs VALUES( '2014-05-06T17:14:00Z', '2014-05-06T17:14:00Z', 'ISO 8601 Zulu' );
INSERT 0 1
test=# INSERT INTO tzs VALUES( '2014-05-06T17:14:00-04:00', '2014-05-06T17:14:00-04:00', 'ISO 8601 offset' );
INSERT 0 1
test=# SELECT * FROM tzs ;
@davetapley
davetapley / ab.sh
Created April 17, 2014 21:28
Failing to call res.send(200) in an express app
$ ab -n 1000 -c 1000 http://localhost:3000/hang
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
apr_socket_recv: Connection reset by peer (104)