Skip to content

Instantly share code, notes, and snippets.

View strukturedkaos's full-sized avatar

Don Pottinger strukturedkaos

View GitHub Profile
@strukturedkaos
strukturedkaos / copy_aws_s3.rb
Created July 1, 2014 01:10
Copy files between AWS S3 buckets
s3.buckets['kickdrop-production-assets'].objects['uploads/'].copy_to('uploads/', :bucket_name => 'kickdrop-staging-assets')
source_bucket='kickdrop-production-assets'
target_bucket='kickdrop-staging-assets'
source_key = 'uploads'
target_key = 'uploads'
bucket1 = s3.buckets[source_bucket]
bucket2 = s3.buckets[target_bucket]
obj1 = bucket1.objects.with_prefix("uploads")
obj2 = bucket2.objects.with_prefix("uploads")
#!/usr/bin/env ruby
require 'prime'
class AdditiveFunctionValidator
attr_reader :limit, :prime_numbers
def initialize(limit:)
@limit = limit
@strukturedkaos
strukturedkaos / compond_assignment
Created August 27, 2014 18:54
|= compound assignment example
irb(main):013:0> a = []
=> []
irb(main):014:0> a |= [1]
=> [1]
irb(main):015:0> a |= [1]
=> [1]
irb(main):016:0> a
@strukturedkaos
strukturedkaos / student_presenter.rb
Last active August 29, 2015 14:07
Student Presenter example
# stored in app/presenters/student_presenter.rb
class StudentPresenter < SimpleDelegator
delegate :email, to: :user
def initialize(student)
@student = super(student)
end
def self.find(id)

Data Integrity

Programming is hard. We must valiantly fight complexity on a daily basis. Conditional statements quickly increase the complexity of a system. Every time we’re unsure about a value, we add a conditions to decide how to proceed. If only we could become more confident with the state of the system…

Hurrah! Data integrity can give us this confidence. By constraining our data, we can make some assumptions about the state of the system. Gone are the days of guarding potentially nil values. Out with orphaned and duplicate records! Data is the [life] of our software. Let’s take [life] by the reigns.

@strukturedkaos
strukturedkaos / yard.rb
Created November 20, 2014 20:30
Serving Yard Documentation with Rails and HighVoltage
# config/routes.rb
get "/doc" => "docs#show", id: "index"
get '/doc/*id' => 'docs#show'
# app/controllers/docs_controller.rb
class DocsController < HighVoltage::PagesController
respond_to :html
layout false
def show
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup
import Ember from 'ember';
// ==========================================================================
// Project: Ember EasyForm
// Copyright: Copyright 2013 DockYard, LLC. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
// Version: 1.0.0.beta.1

chruby can be installed in various ways. For OSX, it is as simple as:

brew install chruby

Next, add the two following lines to your shell profile file (.bashrc, .zshrc, etc.)

source '/usr/local/share/chruby/chruby.sh'
source '/usr/local/share/chruby/auto.sh'
@strukturedkaos
strukturedkaos / es.sh
Created June 4, 2015 12:42
Elasticsearch exploration
Setup snapshot repo:
curl -XPUT 'http://localhost:9200/_snapshot/demo_nyc_accidents' -d '{
"type": "url",
"settings": {
"url": "http://download.elasticsearch.org/demos/nycopendata/snapshot/"
}
}'