Skip to content

Instantly share code, notes, and snippets.

# https://stackoverflow.com/a/29299786/512507
def self.valid_id?(id)
case id
when /^[a-zA-Z0-9]{15}$/
return true
when /^[a-zA-Z0-9]{18}$/
id[15..17] == [
id[0..4],
id[5..9],
id[10..14]
@alfius
alfius / elasticsearch.rb
Created September 22, 2016 21:56
A simplified version of our Elasticsearch query library at Wootric, including a few examples
require 'rest-client'
require 'json'
class Elasticsearch
class << self
attr_accessor :url
def configured?
url.present?
end
@alfius
alfius / sunspot.rb
Created November 26, 2014 16:45
Setup Sunspot and Websolr with authentication
# put this file in config/initializers
require 'openssl'
class RSolrWithWebsolrAuth
attr_reader :secret
def initialize(secret)
@secret = secret
@alfius
alfius / nestopia_linux_installation.sh
Created April 27, 2013 20:53
This script installs Nestopia and its dependencies under linux. The resulting binary is created at ./nestopia/nst
sudo apt-get install build-essential libgtk2.0-dev libsdl-dev
mkdir nestopia
cd nestopia
wget -O Nestopia140src.zip http://prdownloads.sourceforge.net/nestopia/Nestopia140src.zip?download
wget http://rbelmont.mameworld.info/nst140_lnx_release_h.zip
unzip Nestopia140src.zip
unzip nst140_lnx_release_h.zip
make
mkdir -p ~/.nestopia
touch ~/.nestopia/nstcontrols
@alfius
alfius / searchability.rb
Last active December 16, 2015 15:19
How to create an RSpec matcher that allows testing whether a page is indexable by search engines or not.
#spec/features/home_spec.rb
require 'spec_helper'
describe 'Home page' do
it 'should be searchable' do
visit '/'
page.should be_searchable
end
end