Skip to content

Instantly share code, notes, and snippets.

@ivanyv
ivanyv / dnsmasq OS X.md
Created February 27, 2018 02:48 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

Install

@ivanyv
ivanyv / ARCH.md
Last active November 14, 2016 21:43
Exploring a monolith Rails architecture based on "domains" (which I call "modules")

Architecture

Modules

The app is organized into "modules" (not Ruby modules), like "Core", "Admin", "Directory", etc.

Each module contains models, controllers, and every other related class.

When I say "modules", I'm actually talking about domains, so why call them modules? I'm actually torn on this as I like how "modules" fits much better. But I also know

@ivanyv
ivanyv / application_form.rb
Created July 21, 2016 23:42
Easy form/service objects and decorators
# app/models/application_form.rb
module ApplicationForm
extend ActiveSupport::Concern
class_methods do
def model_name
# Project::Form.model_name => Project.model_name
name.deconstantize.constantize.model_name
end
end
@ivanyv
ivanyv / application.amp.erb
Created December 12, 2015 02:51
Easy Google AMP on Rails
<html>
<head>
<link rel="canonical" href="<%= current_uri_sans_amp %>">
</head>
...
</html>
Verifying that +ivan is my openname (Bitcoin username). https://onename.io/ivan

Keybase proof

I hereby claim:

  • I am ivanyv on github.
  • I am ivanyv (https://keybase.io/ivanyv) on keybase.
  • I have a public key whose fingerprint is 66D2 81C2 EAFF 19BA 9B22 4404 D0BB 1424 7607 0208

To claim this, I am signing this object:

@ivanyv
ivanyv / globals.rb
Last active December 30, 2015 00:59
Crazy global variables
require 'singleton'
class G
include Singleton
attr_accessor :variables
def self.[](var)
variables[var]
end
@ivanyv
ivanyv / serialize.rb
Created March 17, 2012 04:40
Easy peasy serializer separation for DDD
# app/controllers/users_controller.rb
class UsersController < ApplicationController
respond_to :json, :xml
def show
@user = @user.find(params[:id])
respond_with Serializer(@user)
end
end
# app/models/my_model.rb
module MyApp
module Model
def self.included(base)
base.send :include, Mongoid::Document
base.send :include, Mongoid::Timestamps
base.send :include, ActiveAdmin::Mongoid::Patches
end
end
@ivanyv
ivanyv / chunky_pixels.rb
Created July 1, 2011 22:42
Make chunky pixels the brute force way
require 'rubygems'
require 'chunky_png'
orig = ChunkyPNG::Image.from_file('input.png')
rows = (orig.width / 10.0).ceil
cols = (orig.height / 10.0).ceil
canvas = ChunkyPNG::Canvas.new(rows * 10, cols * 10).replace(orig)
(0...rows).each do |row|
x = row * 10