Skip to content

Instantly share code, notes, and snippets.

View mguterl's full-sized avatar

Mike Guterl mguterl

View GitHub Profile
@xpepper
xpepper / download_rubytapas.rb
Last active January 1, 2019 01:37
This script will download all the published rubytapas. Each episode, with all the attachments, will be downloaded in a folder named after the episode number. For example, in the folder "64" will be downloaded: 064-yield-or-enumerate.html, 064-yield-or-enumerate.mp4, 064-yield-or-enumerate.rb You need to set your credentials (username and passwor…
# username = "my_username"
# pwd = "my_password"
# target_path = "my_target_path"
# saving auth cookie
system %Q{wget --save-cookies /tmp/cookie.txt --keep-session-cookies --post-data "username=#{username}&password=#{pwd}" -O - \
https://rubytapas.dpdcart.com/subscriber/login?__dpd_cart=d08391e6-5fe2-4400-8b27-2dc17b413027}
(25..600).each do |i|
# 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
@skwp
skwp / watch_listing.rb
Last active December 15, 2015 18:09
Hexagonal extraction of a controller action from reverb.com, showing reuse between controller and Grape/Roar based API. This is sample code stripped down to the essentials and is not guaranteed to work as-is :)
class Reverb::Actions::WatchListing
def self.watch(user, product, listener)
if product.owner?(user)
listener.failure(I18n.t('flash.watchlist.error_own'))
else
Reverb::Analytics.track(user, :watch_product) # FIXME, this doesn't belong here
user.user_watch_products.create(:product_id => product.id)
listener.success
end
end
@bkeepers
bkeepers / .gitconfig
Created February 19, 2013 14:12
Git aliases to make new commits that fixup or are squashed into previous commits
[alias]
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autosquash $REV^' -
squash = !sh -c 'REV=$(git rev-parse $1) && git commit --squash $@ && git rebase -i --autosquash $REV^' -
class TripsController < ApplicationController
class Action < ApplicationController::Action
end
class New < Action
expose(:trip) { Trip.new(params[:trip]) }
end
class Create < New
def call
@afeld
afeld / gist:4952991
Last active February 8, 2022 03:13
good APIs for mashups

This list has been superseded by Public APIs. Check there for APIs with Auth: No, HTTPS and CORS Yes.


List of data APIs that require no server-side auth or private credentials, and are thus good for small browser-only JS projects.

@krisleech
krisleech / 01-trips_controller.rb
Created February 13, 2013 22:35
Using focused_controller to provide service object with hooks for callbacks
class TripsController < ApplicationController
class Action < ApplicationController::Action
end
class New < Action
expose(:trip) { Trip.new(params[:trip]) }
end
class Create < New
def call
@mguterl
mguterl / latency.txt
Created February 12, 2013 12:42 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@mislav
mislav / fat-logfiles.sh
Last active December 22, 2018 19:56
Find "*.log" files in your home dir, sort them by fattest-first, and calculate the size of them all together.
find ~ -name '*.log' -print0 | xargs -0 -L1 stat -f'%z %N' | sort -rn | tee fat-logfiles.txt | head
awk '{ total += $1 } END { printf "total: %5.2f MiB\n", total/1024/1024 }' < fat-logfiles.txt
# I don't really see any services here. What I see is:
# - Normal HTTP boundary stuff (params flash, redirect).
# - Model creation and retrieval.
# - Warden manipulation, which is an odd done but smells like boundary.
#
# I left all of the HTTP boundary stuff in the controller (and only the
# controller). I moved the model creation/retrieval into simple class methods
# in the models. I moved the warden manipulation stuff into
# ApplicationController (with caveats that I'll discuss inline).
#