Skip to content

Instantly share code, notes, and snippets.

@wycleffsean
wycleffsean / SassMeister-input-HTML.html
Created March 24, 2014 05:26
Generated by SassMeister.com.
<header>
<span class="logo">Gizmosan</span>
<nav class="site-nav">
<a href="#">TVs</a>
<a href="#">Tablets</a>
<a href="#">PCs</a>
<form>
<input type="search" results=5 placeholder="search..." />
<button>Search</button>
</form>
@wycleffsean
wycleffsean / .bashrc
Last active August 29, 2015 14:07
dot files and tools
if [ -r $HOME/.rbenvrc ];
then
source $HOME/.rbenvrc
fi
if [ -r $HOME/.app_vars ];
then
source $HOME/.app_vars
fi
@wycleffsean
wycleffsean / example.coffee
Created July 17, 2015 05:21
Coffeescript Mixins
Mixin = require './mixin.coffee'
Module = require './module.coffee'
class Logger extends Mixin
yo = (msg) -> console.log msg
class_log: yo
@log: yo
class MyLogger extends Module
@extends Logger
@wycleffsean
wycleffsean / Arel and ActiveRecord.md
Created February 17, 2016 15:30
Arel and ActiveRecord

Join

users = User.arel_table
comments = Comment.arel_table

#select users with comments
User.join(
  users.joins(comments).on(
 users[:id].eq(comments[:user_id])
@wycleffsean
wycleffsean / keybase.md
Created August 4, 2016 03:29
keybase.md

Keybase proof

I hereby claim:

  • I am wycleffsean on github.
  • I am sean_carey (https://keybase.io/sean_carey) on keybase.
  • I have a public key ASDMtr0za7DM5LVpJAR2Y5cvKrT-vz9MESI7MstPnInMIAo

To claim this, I am signing this object:

@wycleffsean
wycleffsean / dump_seeds.rake
Created September 1, 2016 17:25
Dump entire database into seeds
namespace :db do
task dump_seeds: :environment do
Rails.application.eager_load!
path = 'db/fixtures/gen/%s.rb'
ObjectSpace.each_object(Class)
.select{|c| c < ActiveRecord::Base && !c.abstract_class? }
.each do |c|
# skip if it's a view
next if c.new.readonly?
next unless c.attribute_names.include?('id')
@wycleffsean
wycleffsean / accio.rake
Created December 9, 2016 17:10
Heroku Accio DB
namespace :accio do
desc "Drop/restore database from Heroku backup"
task :db do
Rake::Task['accio:download_backup'].invoke
Rake::Task['accio:restore_backup'].invoke
end
desc "Download database dump from Heroku"
task :download_backup => [:logger_no_env, '~/.netrc'] do |t, args|
return Rails.logger.error('curl not installed') unless \
@wycleffsean
wycleffsean / fiber_sleep.rb
Last active February 4, 2019 21:54
Fiber Sleep
require 'fiber'
require 'concurrent' # gem install concurrent-ruby
Thread.abort_on_exception = true
class Async
def self.perform(&block)
instance = new
instance.instance_eval(&block)
until instance.dispatched.value.zero? do
unless instance.yields.empty?
@wycleffsean
wycleffsean / grouping.rb
Created June 6, 2017 21:42
Grouping by expression
require 'securerandom'
require 'pp'
Ex = Struct.new(:a,:b,:c,:d)
module Enumerable
def group(&block)
groups = Hash.new
each do |item|
matches = []
@wycleffsean
wycleffsean / example.rb
Created August 11, 2017 07:41
Ruby Peach
def self.gzip_to_s3
s3_bucket = Aws::S3::Resource.new(region:'us-east-1')
.bucket('basf-content-server')
total = SalesDataDocument.count
docs = SalesDataDocument.all
Peach.enum_for(docs).each do |doc, queue|
progress = total - queue.length
Rails.logger.info <<-LOG if (progress % 20).zero?
storing document ##{progress} of #{total}
LOG