Skip to content

Instantly share code, notes, and snippets.

View gealgaro's full-sized avatar

German Garcia gealgaro

View GitHub Profile
@ipbastola
ipbastola / jq to filter by value.md
Last active April 25, 2024 17:14
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)

require "test/unit"
require "rubygems"
begin ; require "turn" ; rescue LoadError ; end
require "active_support/core_ext/hash/indifferent_access"
class TestHashes < Test::Unit::TestCase
def setup
@hash1 = key_value('a', 1)
@hash2 = key_value('a', 1).with_indifferent_access
end
require "minitest/autorun"
begin ; require "turn" ; rescue LoadError ; end
require "active_support/core_ext/hash/indifferent_access"
class TestHashes < MiniTest::Unit::TestCase
def setup
@hash1 = {a: 1}
@hash2 = {a: 1}.with_indifferent_access
end
module NavigationHelpers
# Put helper methods related to the paths in your application here.
def homepage
"/"
end
def tour_page
"/tour"
end
require File.expand_path(File.dirname(__FILE__) + '/request_helper')
feature "Users sign in", %q{
In order to start using the page
As an anonymous user
I want sign in to my existing account
} do
background do
@user = Factory.create(:user)
@guilleiguaran
guilleiguaran / no_overlapping_validation.rb
Created June 30, 2011 06:10
Simple No Overlapping Validation
class NoOverlappingValidator < ActiveModel::Validator
def validate(record)
message = options[:message] || "Record is invalid"
start = record.read_attribute(options[:start])
finish = record.read_attribute(options[:finish])
klass = record.class
t = klass.arel_table
c1 = t[:start].lt(finish).and(t[:start].gteq(start))
c2 = t[:finish].gt(start).and(t[:finish].lteq(finish))
c3 = t[:start].lteq(start).and(t[:finish].gteq(finish))