Skip to content

Instantly share code, notes, and snippets.

Benjamin Fleischer bf4

Block or report user

Report or block bf4

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bf4
bf4 / setup-pow.bash
Created Nov 10, 2015
pow and powprox install/reinstall
View setup-pow.bash
#!/usr/bin/env bash
install() {
brew cask list lunchy >/dev/null || brew cask install lunchy
pwd=$(pwd)
reinstall_openssl
reinstall_nginx
cd # In case user uses gemsets, ensure we're installing powder outside of a project
@bf4
bf4 / README.md
Last active Jun 30, 2017
clone_all repos
View README.md

Clone all repos

Install as follows

\curl -sSL https://gist.github.com/bf4/c19f041bb0887476dfaa/download | \
  tar xzvf - --include '*setup' -O | bash

optionally first set PROJECT_DIR and PROJECT_CLONE_URL in your ~/.profile

@bf4
bf4 / reminder.py
Created Nov 25, 2015 — forked from bmaca/reminder.py
A python program to remind you to take a break every hour on your 8 hour work shift ;)
View reminder.py
import time
import webbrowser
total_breaks = 8
break_count = 0
while (break_count < total_breaks):
time.sleep(3600)
webbrowser.open("https://31.media.tumblr.com/288d6e631cd930de65547ef5044fefb8/tumblr_mlksb86paT1qbuvyto1_500.gif")
break_count = break_count + 1
View associations.rb
# use inverse_of to 'just work'
class User < ActiveRecord::Base
has_many :contributions, inverse_of: :user
has_many :posts, through: :contributions
end
class Post < ActiveRecord::Base
has_many :contributions, inverse_of: :post
has_many :contributors, through: :contributions,
source: :user
@bf4
bf4 / ams.rb
Created Apr 3, 2017 — forked from sineed/ams.rb
Upgrade AMS from 0.9.0 to 0.10.0
View ams.rb
module AMS
module V09
class Serializer < ActiveModel::Serializer
def serializable_hash(adapter_options = nil,
options = {},
adapter_instance = self.class.serialization_adapter_instance)
object.nil? ? nil : super
end
end
@bf4
bf4 / find_relations_in_batches.rb
Created Mar 22, 2017
ActiveRecord Rails Find Relations in Batches
View find_relations_in_batches.rb
# Finds and yields relations in batches. Adapted from record.find_in_batches since that yields
# arrays and we want to operate on relationships.
# Adapted from:
# https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/relation/batches.rb#L98-L115
def find_in_batches(target, batch_size: default_batch_size, start: nil)
relation = target
if logger && (target.arel.orders.present? || target.arel.taken.present?)
logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
relation = relation.reorder(target.send(:batch_order)).limit(batch_size)
View learn_clojure_recipe.md
@bf4
bf4 / go_kinesis_with_structs.go
Created Mar 14, 2017 — forked from pricees/go_kinesis_with_structs.go
Go + AWS Kinesis + Encode/Decode Structs
View go_kinesis_with_structs.go
/**
NOTE:
Assumes env contains aws credentials:
AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY
AWS_SECRET_KEY_ID or AWS_SECRET_KEY
and AWS_REGION_NAME (e.g. 'US-EAST-1')
see EnvAuth() below
*/
View 2014-09-30-sample.rb
message.to = 'Person Name <person@example.com>'
message.subject = 'Sample Subject'
# body is probably good enough, but you can set text_part/html_part below if you like
message.body = <<HERE.strip
Hey-
This is a sample
Thanks
HERE
You can’t perform that action at this time.