Skip to content

Instantly share code, notes, and snippets.

@milesmatthias
milesmatthias / directory_upload.rb
Created September 1, 2014 00:57
S3 directory upload in ruby. Switched http://avi.io/blog/2013/12/03/upload-folder-to-s3-recursively to use the official aws ruby sdk.
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
class S3FolderUpload
attr_reader :folder_path, :total_files, :s3_bucket
attr_accessor :files
@biomancer
biomancer / dep_detect.rb
Last active March 20, 2017 16:04
Dirty simple order dependencies detector
## This script can be used to detect simple order dependencies if one of tests is failing when some other test(or tests, independently) is being run before it.
## Script will not give reliable results if the dependency is complex - e.g. two specific tests must be run before for affected one to fail.
## Script will refine results with each rspec run: more runs will result smaller UNSAFE lists. Files from previous script runs are used too
## Ensure that you have config.order = 'random' in RSpec.configure block .
## Running rspec with different seeds to collect data
RSPEC_RUN_COUNT = 5 #set to 0 to analyze already existing rspec_*.txt files
RSPEC_RUN_COUNT.times do
@otobrglez
otobrglez / jaccard_recommendation.rb
Last active April 2, 2024 17:51
Simple recommendation system written in Ruby based on Jaccard index.
# Simple Recommendation Engine in Ruby
# Visit: http://otobrglez.opalab.com
# Author: Oto Brglez <otobrglez@gmail.com>
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@willkoehler
willkoehler / document_uploader.rb
Created February 11, 2014 15:14
Carrier uploader for documents that creates thumbnails from images and PDFs
class DocumentUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
# Store on Amazon S3 using Fog
storage :fog
# Directory where uploaded files will be stored.
def store_dir
"documents/#{model.id}"
end
@romansklenar
romansklenar / 20131118172653_create_transactional_items_view.rb
Last active July 3, 2017 09:15
Using PostgreSQL's materialized views as background for ActiveRecord models for flexible statistics
# db/migrate/20131118172653_create_transactional_items_view.rb
class CreateTransactionalItemsView < ActiveRecord::Migration
def up
select_sql = File.open("#{Rails.root}/db/migrate/20131118172653_create_transactional_items_view.sql", 'r') { |f| f.read }
# for materialized view:
view_sql = "CREATE MATERIALIZED VIEW transactional_items AS (#{select_sql})"
# for normal view:
view_sql = "CREATE VIEW transactional_items AS (#{select_sql})"
@turboladen
turboladen / psql_encoding.sql
Created October 2, 2013 08:46
Script for dealing with creating Postgres databases that complain with: ``` PG::InvalidParameterValue: ERROR: encoding UTF8 does not match locale en_US DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1. ``` ...when trying to create the production DB. Taken from: http://stackoverflow.com/questions/13115692/encoding-utf8-does-not-match-…
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active March 7, 2024 03:56
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@willurd
willurd / Getting started with requirejs.md
Last active December 14, 2022 08:15
A short introduction to require.js

This is a small collection of scripts showing how to use require.js. It's only one of several ways of setting up a require.js project, but it's enough to get started.

At its core, require.js is about three things:

  1. Dependency management
  2. Modularity
  3. Dynamic script loading

The following files show how these are achieved.

@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active April 17, 2024 10:51
Backend Architectures Keywords and References

Using vagrant

Install

  • Install VirtualBox
  • Install vagrant (use the OS installer instead of gem)

Setup

  • vagrant box add <box_name> <box_url>