Skip to content

Instantly share code, notes, and snippets.

View danieldraper's full-sized avatar

Daniel Draper danieldraper

View GitHub Profile
@danieldraper
danieldraper / 1_brand.rb
Created August 27, 2019 01:11 — forked from KamilLelonek/1_brand.rb
Repository pattern example in Ruby for Rails developers
module Storage
module Models
class Brand < ActiveRecord::Base; end
end
end
@danieldraper
danieldraper / application_form.rb
Last active September 10, 2020 06:17
Service object and form object using ActiveModel and dry-rb
require "dry/monads/result"
class ApplicationForm
include Dry::Monads::Result::Mixin
include ActiveModel::Model
def self.attribute(name, options = {})
self.send(:attr_accessor, name)
_attributes << Attribute.new(name, options)
end
@danieldraper
danieldraper / c10k.ru
Created October 30, 2018 07:23 — forked from WJWH/c10k.ru
The double hijack trick, serving 65k connections from a single ruby process
# This server demo does a socket hijack in Rack and then saves the socket to a global variable
# to prevent it from being GCed when the Puma thread ends. It will then write "BEEP" to each
# socket every ten seconds to prevent the connection timing out. During testing, it easily
# handled up to 65523 connections, after which it ran into the `ulimit` for open file descriptors.
# The bit with the waiting area is there because a normal `Set` is not thread safe and it would
# drop socket due to race conditions. The `Queue` is thread safe and will make sure all sockets
# are preserved.
# run with `rackup -q -p 8000 -o 0.0.0.0 c10k.ru`
# testing: install `ab` and then run `ab -c 20000 -n 20000 <ip adress of server>:8000/

Keybase proof

I hereby claim:

  • I am danieldraper on github.
  • I am danieldraper (https://keybase.io/danieldraper) on keybase.
  • I have a public key ASCfuMuR4m8woN178kkL1YBWUICBZ9M-VQMHAW7OGE3s4Qo

To claim this, I am signing this object:

#!/usr/bin/env bash
# Author: Daniel Draper
# Credit:
# - https://github.com/vdka/dotfiles/
# - https://github.com/mathiasbynens/dotfiles
# Install rbenv.
brew install rbenv
#!/usr/bin/env bash
# Author: Daniel Draper
# Credit:
# - https://github.com/vdka/dotfiles/
# - https://github.com/mathiasbynens/dotfiles
# Ask for the administrators password.
sudo -v
#!/usr/bin/env bash
# Author: Daniel Draper
# Credit:
# - https://github.com/vdka/dotfiles/
# - https://github.com/mathiasbynens/dotfiles
# Ask for the administrators password.
sudo -v
@danieldraper
danieldraper / beanstalk_nginx.conf
Created April 3, 2016 23:20 — forked from petelacey/beanstalk_nginx.conf
Nginx always-on SSL config for ElasticBeanstalk
files:
"/etc/nginx/conf.d/000_APP_NAME.conf":
mode: "000755"
owner: root
group: root
content: |
upstream APP_NAME_app {
server unix:///var/run/puma/my_app.sock;
}
@danieldraper
danieldraper / Dockerfile
Last active September 8, 2015 00:13 — forked from robjacoby/Dockerfile
Ruby/Rails Dockerfiles
# ---------------------------------------------------------------------------
# This is the Dockerfile to build the base image for ruby/rails/mysql
# ---------------------------------------------------------------------------
FROM debian:jessie
MAINTAINER XXX
ENV REFRESHED_AT 2015-08-07
# ---------------------------------------------------------------------------
@danieldraper
danieldraper / bash_profile
Created June 9, 2015 00:24
Change git author email per directory
function git () {
case "$PWD"; in
/path/to/work/repos/*)
command git -c user.email=you@work.com "$@"
;;
*)
command git "$@"
;;
esac
}