Skip to content

Instantly share code, notes, and snippets.

@ftrain
ftrain / rhymes.clj
Last active July 14, 2023 22:20
Annotated rhyming dictionary
;; This is at: https://gist.github.com/8655399
;; So we want a rhyming dictionary in Clojure. Jack Rusher put up
;; this code here:
;;
;; https://gist.github.com/jackrusher/8640437
;;
;; I'm going to study this code and learn as I go.
;;
;; First I put it in a namespace.
@radu-gheorghe
radu-gheorghe / log_backup.bash
Created July 26, 2012 08:31
Optimize&Backup Elasticsearch index. And restore.
#!/usr/bin/env bash
###############FUNCTIONS############
function prepare {
#optimize the index
echo -n "Optimizing index $INDEX_NAME..."
curl -XPOST "$ADDRESS/$INDEX_NAME/_optimize" 2>/dev/null| grep 'failed":0' >/dev/null
if [ $? -eq 0 ]; then
echo "done"
@mattwynne
mattwynne / sketch.rb
Created June 23, 2012 22:22 — forked from lukemelia/sketch.rb
sketch for Matt Wynne
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@saetia
saetia / gist:1623487
Last active March 20, 2025 09:04
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@amiel
amiel / custom_validation_matcher.rb
Created December 24, 2011 03:32
I was fed up with "expected valid? to return true". Now you get errors
module CustomValidationMatcher
class IsValid
def matches?(target)
@target = target
@target.valid?
end
def failure_message
"expected #{ @target.class.name } to be in valid, errors were: #{ @target.errors.full_messages.inspect }"
/* Simple producer-consumer example using coroutines */
// Our counter
counter := 0
// Indicate we're done
done := false
// Increment a counter by n up to y
produce := method(n, y,
loop(
@FND
FND / .gitignore
Created October 28, 2011 08:38
test case for apparent bug regarding association inheritance
Gemfile.lock
@dkubb
dkubb / veritas_migration.rb
Created October 11, 2011 06:48
Example data migration using Veritas
class MyMigration < Veritas::Migration
def call
# Transformations
# ---------------
# 1) remove all columns except id, name and email
# 2) rename user_id to id
# 3) add a boolean active column, setting the default to false
# 4) add a constraint on name where it must be between 1 and 100 characters
@dkubb
dkubb / .rvmrc
Created August 10, 2011 22:44
Web framework Spike
rvm use @$(basename `pwd`) --create
@onethirtyfive
onethirtyfive / gist:1083182
Created July 14, 2011 19:06
Class-Table Inheritance Meta-model for DataMapper
# This example is an alternative to implementing polymorphic associations
# using an ActiveRecord-esque 'type' column. In this model, there are many
# 'units.' Unit is an abstract supertype. Descendants are modeled referencing
# a unit by 'unit_id', a foreign key to the primary key in the units model.
# Note: This approach maintains referential integrity in the database via
# descendants' FK to unit.id; however, it is the application's responsibility
# to ensure that no two descendants reference the same unit. This is an
# intrinsic limitation of the "Class Table Inheritance" approach, but it's
# a lot better than maintaining "type" data that is opaque to the data store.