This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl XPUT -d '{"settings":{"analysis":{"filter":{"ngram":{"type":"nGram","min_gram":3,"max_gram":25}},"analyzer":{"ngram":{"tokenizer":"whitespace","filter":["lowercase","stop","ngram"],"type":"custom"},"ngram_search":{"tokenizer":"whitespace","filter":["lowercase","stop"],"type":"custom"},"analyzer_startswith":{"tokenizer":"keyword","filter":"lowercase"}}}},"mappings":{"document":{"properties":{"id":{"type":"integer","index":"not_analyzed","store":true},"email":{"type":"string","tokenizer":"uax_url_email"},"first_name":{"type":"string","index_analyzer":"ngram","search_analyzer":"ngram_search"},"last_name":{"type":"string","index_analyzer":"ngram","search_analyzer":"ngram_search"},"mobile":{"type":"string","index_analyzer":"analyzer_startswith","search_analyzer":"analyzer_startswith"},"nhs_number":{"type":"string","index_analyzer":"ngram","search_analyzer":"ngram_search"},"primary_account_id":{"type":"integer"}}}}}' http://localhost:9200/test_service_users | |
curl XPUT -d '{"first_name":"Ronald","last_name":"Mc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.search(q, options={}) | |
query = { | |
:query => { | |
:bool => { | |
:should => [ | |
{:match => {:_all => q}}, | |
{:match => {:mobile => {:query => q, :type => "phrase_prefix"}}} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node "rackspace-search" inherits rackspace { | |
firewall {'920 accept es http': | |
port => 9200, | |
proto => 'tcp', | |
action => 'accept', | |
} | |
firewall {'930 accept es tcp': | |
port => 9300, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with stddeviation as ( | |
select stddev(extract (epoch from coalesce(deactivated_at, now()) - created_at)) as s from users where type = 'ServiceUser' | |
), | |
average as ( | |
select avg(extract (epoch from coalesce(deactivated_at, now()) - created_at)) as a from users where type = 'ServiceUser' | |
) | |
select avg(coalesce(deactivated_at, now()) - created_at) as average | |
from users, average, stddeviation | |
where type = 'ServiceUser' | |
and extract(epoch from coalesce(deactivated_at, now()) - created_at) < average.a + (stddeviation.s * 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"log" | |
"io" | |
"io/ioutil" | |
"os" | |
"github.com/gorilla/mux" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"log" | |
"io" | |
"io/ioutil" | |
"os" | |
"github.com/gorilla/mux" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
omarqureshi=# create unique index foos_some_field_idx on foos(some_field); | |
CREATE INDEX | |
omarqureshi=# insert into foos(some_field) values (null); | |
INSERT 0 1 | |
omarqureshi=# insert into foos(some_field) values (null); | |
INSERT 0 1 | |
omarqureshi=# insert into foos(some_field) values ('a'); | |
INSERT 0 1 | |
omarqureshi=# insert into foos(some_field) values ('a'); | |
ERROR: duplicate key value violates unique constraint "foos_some_field_idx" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# upgrade all packages | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get update | |
apt-get -y upgrade | |
# Install brightbox ruby repository | |
apt-get install -y python-software-properties | |
apt-add-repository -y ppa:brightbox/ruby-ng |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
$connection = Fog::Compute.new({:provider => "Rackspace", :rackspace_username => "xxx", :rackspace_api_key => "xxx", :rackspace_region => :lon}) | |
def get_servers(stage, role) | |
$connection.servers.select {|s| s.name =~ Regexp.new("^#{role}\-(.*)\.#{stage}\.buddyapp\.org$")}.map(&:ipv4_address) | |
end | |
role :web, *get_servers("staging", "web") | |
role :app, *get_servers("staging", "app") | |
role :jobs, *get_servers("staging", "jobs") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node "rackspace-database" inherits base { | |
exec{"create-fs": | |
command => "mkfs -t ext3 /dev/xvde1", | |
user => 'root', | |
path => ['/usr/bin','/sbin'], | |
timeout => 0, | |
unless => "/usr/bin/file -s /dev/xvde1 | /bin/grep ext3", | |
} | |
file {"/var/lib/postgresql": |