Skip to content

Instantly share code, notes, and snippets.

Ivan ivanyv

Block or report user

Report or block ivanyv

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
@ivanyv
ivanyv / dnsmasq OS X.md
Created Feb 27, 2018 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X
View dnsmasq OS X.md

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 Nov 14, 2016
Exploring a monolith Rails architecture based on "domains" (which I call "modules")
View ARCH.md

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 Jul 21, 2016
Easy form/service objects and decorators
View application_form.rb
# 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 Dec 12, 2015
Easy Google AMP on Rails
View application.amp.erb
<html>
<head>
<link rel="canonical" href="<%= current_uri_sans_amp %>">
</head>
...
</html>
View gist:379d0fbf6ca0853785c6
Verifying that +ivan is my openname (Bitcoin username). https://onename.io/ivan
View keybase.md

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 Dec 30, 2015
Crazy global variables
View globals.rb
require 'singleton'
class G
include Singleton
attr_accessor :variables
def self.[](var)
variables[var]
end
@ivanyv
ivanyv / serialize.rb
Created Mar 17, 2012
Easy peasy serializer separation for DDD
View serialize.rb
# 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
View base_model.rb
# 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 Jul 1, 2011
Make chunky pixels the brute force way
View chunky_pixels.rb
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
You can’t perform that action at this time.