Skip to content

Instantly share code, notes, and snippets.

View nz's full-sized avatar

Nick Zadrozny nz

View GitHub Profile
@nz
nz / named pipe queues.sh
Created October 9, 2013 05:31
Nerd sniped by named pipes
#!/bin/sh
# clear old pipe and lock
rmdir worklock 2>/dev/null
rm work
if [[ ! -p work ]]; then
mkfifo work
else
dd if=work of=/dev/null
@nz
nz / 1-migration.rb
Last active December 22, 2015 07:49
Simple asynchronous batch indexing with Sunspot. Currently an untested work-in-progress, I expect to refactor and contribute this to Sunspot proper.
# rails generate migration add_indexed_at_to_searchable_models
class AddIndexedAtToSearchableModels
TABLES = [ :articles, :authors, :comments ]
def self.up
TABLES.each do |name|
change_table(name) do |t|
t.integer :indexed_at
end
@nz
nz / gist:6427811
Last active December 22, 2015 05:59
Multi model search with Sunspot

Create a search controller on the command line

rails generate controller search

Add a route for /search in config/routes.rb

get 'search' => 'search#search', :as => :search
@nz
nz / gist:6322673
Created August 23, 2013 18:46
Basic sketch for renaming an index in Elasticsearch
# create an index with some state (in this case, a mapping)
curl -X POST localhost:9200/test-original -d '{"mappings":{"wine":{"properties":{"designation":{"type":"string"},"full_name":{"type":"string"},"winery":{"type":"string"},"style":{"index":"no","type":"string"},"vintage":{"index":"no","type":"string"},"restaurant_ids":{"index":"no","type":"string"},"appellation":{"type":"string"},"vineyard_name":{"type":"string"},"variety_id":{"index":"no","type":"string"},"country":{"type":"string"}}}}}'
# => {"ok":true,"acknowledged":true}
# verify the mapping
curl localhost:9200/test-original/_mapping
# => {"test-original":{"wine":{"properties":{"appellation":{"type":"string"},"country":{"type":"string"},"designation":{"type":"string"},"full_name":{"type":"string"},"restaurant_ids":{"type":"string","index":"no"},"style":{"type":"string","index":"no"},"variety_id":{"type":"string","index":"no"},"vineyard_name":{"type":"string"},"vintage":{"type":"string","index":"no"},"winery":{"type":"string"}}}}}
# copy the inde
@nz
nz / websolr_authenticated_connection.rb
Last active February 16, 2018 21:46
Support in Sunspot for Websolr Advanced Auth
require 'openssl'
class RSolrWithWebsolrAuth
attr_reader :secret
def initialize(secret)
@secret = secret
end
@nz
nz / tattoo.rb
Created July 31, 2013 20:48
Hashtat brainstorming with @tinasoul
class Tattoo
searchable do
text :title
text :description
text :studio
text :body_location
string :body_location do
body_location.split(/ /)
@nz
nz / foobar.monit.conf
Created June 12, 2013 22:52
My typical monit + Upstart combination.
check process foobar with pidfile /var/run/foobar.pid
start program = "/sbin/start foobar"
stop program = "/sbin/stop foobar"
if mem usage > 2%
for 2 cycles
then restart
if failed host 127.0.0.1 port 8000 protocol HTTP
{
"filter": {
"and": [
{ "filter": "1" },
{
"or": [
{ "filter": 2 },
{ "filter": 3 },
{ "filter": 4 }
]
@nz
nz / drupal-apachesolr-stats-workaround.diff
Created March 19, 2013 05:34
Drupal's apachesolr module is polling /admin/stats.jsp, which is disabled on Websolr for security reasons. This is a workaround.
--- Drupal_Apache_Solr_Service.php.bak 2013-03-13 15:50:28.000000000 -0700
+++ Drupal_Apache_Solr_Service.php 2013-03-13 14:19:54.000000000 -0700
@@ -78,7 +78,7 @@
const SEARCH_SERVLET = 'select';
const LUKE_SERVLET = 'admin/luke';
const SYSTEM_SERVLET = 'admin/system';
- const STATS_SERVLET = 'admin/stats.jsp';
+ #const STATS_SERVLET = 'admin/stats.jsp';
/**

Hello everyone,

Good news! After seven months of a widely adopted pre-release, Sunspot 2.0.0.pre has just been released as Sunspot 2.0.

  Successfully built RubyGem
  Name: sunspot
  Version: 2.0.0
  File: sunspot-2.0.0.gem