Skip to content

Instantly share code, notes, and snippets.

View chatter's full-sized avatar
:octocat:
﴾͡๏̯͡๏﴿ O'RLY?

Curtis Hatter chatter

:octocat:
﴾͡๏̯͡๏﴿ O'RLY?
View GitHub Profile
desc 'Create YAML test fixtures from data in an existing database.
Defaults to development database. Set RAILS_ENV to override.'
task :extract_fixtures => :environment do
sql = "SELECT * FROM %s"
skip_tables = ["schema_info"]
ActiveRecord::Base.establish_connection
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
i = "000"
#!/bin/bash
#
# god
#
# chkconfig: - 85 15
# description: start, stop, restart God (bet you feel powerful)
#
RETVAL=0
@chatter
chatter / texis
Created May 27, 2009 18:58
init.d script for texis database
#!/bin/bash
#
# texis
#
# chkconfig: - 85 15
#
# description: start, stop, restart Texis
#
RETVAL=0
curl -XGET http://localhost:9200/youthletics/program/_search -d '{"query": { "match_all": {} },
"facets": {
"avg_price": {
"terms_stats": {
"key_field": "_parent",
"value_field": "registration.cost",
"order": "mean"
},
"facet_filter": {
"terms": { "sport": ["soccer"] }
@chatter
chatter / es_missing_filter.bash
Last active December 21, 2015 09:08
Examples of searching for null values or missing fields
# uses "null_value" to set default value if field is missing and then add that
# to the terms query.
# requires change to mapping that you index the necessary field with "null_value": "NOT APPLICABLE"
# "NOT APPLICABLE" can be anything you want.
curl -XGET http://localhost:9200/youthletics/organization/_search -d '{
"query": { "match_all": {} },
"filter": {
"has_child": {
"type": "program",
"filter": {
@chatter
chatter / sort_by_avg_price.bash
Created August 20, 2013 20:19
example of sorting organizations based on child programs registration cost
# first: notice the need to fully specify 'program' in 'script' field, due to
# https://github.com/elasticsearch/elasticsearch/issues/3285
#
# this will create a custom_score based on the avg of program's registration cost
# the value is negated so that it sorts cheapest to highest
#
# this example filters organizations on programs: sport and community
curl -s -XGET http://172.19.0.48:9200/youthletics/organization/_search -d '{
"query": {
"has_child": {
def reindex(name, &block)
Tire::Search::Scan.new(name, &block).each do |results|
documents = results.map do |document|
document.to_hash.except(:type, :_index, :_explanation, :_score, :highlight, :sort)
end
Tire.index(name).bulk_store documents
end
end
defmodule AdventOfCode do
def start(path) do
results = File.stream!(path, [:read, :utf8], :line)
|> Enum.map(&type_of/1)
|> my_map(%{})
results["a"]
end
'''
defmodule Wav do
defstruct size: 0, audio_format: 0, number_of_channels: 0, sample_rate: 0,
byte_rate: 0, block_align: 0, bits_per_sample: 0, bytes_in_data: 0,
samples: []
@format %{1 => :pcm, 3 => :ieee_float, 6 => :alaw, 7 => :mulaw, 65534 => :extensible}
@doc """
Parses a a WAV file with 16 byte fmt sub-chunk.
"""
private func copyConstraints(sourceView: UIView, toView: UIView) {
for constraint in sourceView.superview!.constraints {
if let firstItem = constraint.firstItem as? UIView where firstItem == sourceView {
sourceView.superview?.addConstraint(NSLayoutConstraint(item: toView, attribute: constraint.firstAttribute, relatedBy: constraint.relation, toItem: constraint.secondItem, attribute: constraint.secondAttribute, multiplier: constraint.multiplier, constant: constraint.constant))
} else if let secondItem = constraint.secondItem as? UIView where secondItem == sourceView {
sourceView.superview?.addConstraint(NSLayoutConstraint(item: constraint.firstItem, attribute: constraint.firstAttribute, relatedBy: constraint.relation, toItem: toView, attribute: constraint.secondAttribute, multiplier: constraint.multiplier, constant: constraint.constant))
}
}
}