Skip to content

Instantly share code, notes, and snippets.

View spaghetticode's full-sized avatar
🪲
bugs, bugs everywhere

Andrea Longhi spaghetticode

🪲
bugs, bugs everywhere
View GitHub Profile
@spaghetticode
spaghetticode / gist:1537002
Created December 30, 2011 00:56
TestUnit cheatsheet
assert(boolean,[msg])
Ensures that the object/expression is true.
assert_block([msg]) { block }
Most basic assertion
assert_equal(obj1, obj2, [msg])
Ensures that obj1 == obj2 is true.
assert_in_delta(expecting, actual, delta, [msg])
@spaghetticode
spaghetticode / gist:1691691
Created January 28, 2012 00:04
cronaca di un refactoring
# Giovedì e venerdì io e il Racco ci siamo messi a sistemare le spec rotte di miumiu, siamo subito giunti alla conclusione che urgeva un
# refactoring serio di alcune parti basilari del codice dell'estore. Quanto segue è la cronaca di questo refactoring.
#
# 1) la classe presentava pochi metodi, sembrava poco codice, ma era decisamente denso e oscuro, faceva troppe cose: si
# trattava fondamentalmente un grumo di merda che settava una pletora di variabili di istanza.
# Il codice era speccato, ma le spec erano indecenti e quasi tutte fallivano poiché erano
# disallienate col codice corrente. Fixarle sarebbe costato molta fatica visto che:
# - i blocchi before lunghi e decisamente oscuri
# - il codice dei test era lungo e decisamente oscuro
# Le spec probabilmente non coprivano un numero sufficiente di casistiche, questo era dovuto principalmente al fatto che pochi metodi
@spaghetticode
spaghetticode / minitest_spec_expectations.md
Created March 15, 2012 08:39 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@spaghetticode
spaghetticode / gist:2180864
Created March 24, 2012 10:17
Solution to quiz n. 0
# game 0
class Combinator
def initialize(source)
@columns = (File.readlines(source) rescue source).map{|line| line.chomp.split(//)}
end
def combine
letters = @columns.shift
@columns.empty? ? letters : build_words(letters)
@spaghetticode
spaghetticode / gist:2267162
Created March 31, 2012 18:00
Mikamai Coding Contest: #3
class Maze
BREADCRUMBS = '.'
WALKABLE = ' '
WALL = 'X'
DEAD_END = 'D'
attr_reader :map, :coords
def initialize(map)
@map = map
@spaghetticode
spaghetticode / gist:2884381
Created June 6, 2012 20:04
environment variables in ruby
Pseudo variables
self the receiver of the current method
nil the sole instance of the Class NilClass(represents false)
true the sole instance of the Class TrueClass(typical true value)
false the sole instance of the Class FalseClass(represents false)
__FILE__ the current source file name.
__LINE__ the current line number in the source file.ù
@spaghetticode
spaghetticode / 01.introduction.md
Last active October 18, 2018 08:40
Elasticsearch Introduction

Introduction

Installation on the development machine

We're going to use our development machine in order to build the knowledge on elasticsearch and its usage. If you're on OSX like us, you can install elasticsearch with a simple brew install elasticsearch. Follow the instruction to start the server and to autostart the service at boot. If you are on a different platform you can go to http://www.elasticsearch.org/download/ and choose your preferred installation way.

Now we need to install the elasticsearch development console. Change directory to the elasticsearch installation (you can find it with which elasticsearch... in my case it's /usr/local) and install the marvel plugin: bin/plugin -i elasticsearch/marvel/latest

@spaghetticode
spaghetticode / 02.queries.md
Last active October 18, 2018 08:40
Query Interface

Search

I'm going to discuss the following part of your request:

d) search: search entries
        inputs:
          -entry set identifier
          -three word lists:
 -words that should match
@spaghetticode
spaghetticode / 03.queries.md
Last active October 18, 2018 08:40
More queries

-OR (better), if feasible:

whole phrases instead of words for context-awareness

Let's see some possible solutions. This one will look for the three words in the body, but requires that only 2 of them are present:

GET /docs/doc/_search
{
  "query": {
    "match": {
@spaghetticode
spaghetticode / 04.fuzzy.md
Last active October 18, 2018 08:39
Queries continued - fuzzy search

Fuzzy query

Basic fuzzy queries:

GET /docs/doc/_search
{
  "query": {
    "fuzzy": {
      "body": "robot"