Skip to content

Instantly share code, notes, and snippets.

View oinak's full-sized avatar

Fernando Martínez oinak

View GitHub Profile
@oinak
oinak / README.md
Last active March 21, 2024 11:59
A meditation on Sandi Metz's "Make Everything the Same" blog post

Sandi Metz's blog post:

Make Everything The Same

Upon reading I decided to try an implement Sandi's concept before lookig at her code.

It wasn't worth a dime in comparison, but after reading her code, I decided to try and improvise from there.

Of course, this is no more than remixing the composition from a genius to feel your own style on it. But it was a interesting exercise. I opted for a module with no state and pure functions.

@oinak
oinak / .dockerignore
Last active September 26, 2023 20:09
Boilerplate to jump start a new rails application in docker and docker-compose
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
/public/packs/*
!/log/.keep
!/tmp/.keep
.DS_Store
.env.development
.env.staging
@oinak
oinak / Dockerfile
Last active June 26, 2022 00:47 — forked from anonymous/Dockerfile
Example docker config for rails develompent
FROM ruby:2.4
## In case of postgresql for heroku:
# RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgeresql.list \
# && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
# && apt-get update \
# && apt-get update \
# && apt-get install -y --no-install-recommends \
# postgresql-client-9.6 pv ack-grep ccze unp htop vim \
# && rm -rf /var/lib/apt/lists/* \

Exercise:

Given this calls:

Taskman.queue(2.5) { print 'world!' }
Taskman.queue(1.0) { print 'hello ' }

When we do this one:

Taskman.work
@oinak
oinak / facebook-contact-info-summary.rb
Created March 23, 2018 06:15 — forked from dylanmckay/facebook-contact-info-summary.rb
A Ruby script for collecting phone record statistics from a Facebook user data dump
#! /usr/bin/env ruby
# This script can be used to parse and dump the information from
# the 'html/contact_info.htm' file in a Facebook user data ZIP download.
#
# It dumps all cell phone call + SMS message + MMS records, plus a summary of each.
#
# Place this script inside the extracted Facebook data download folder
# alongside the 'html' folder.
#

A very classy snake

I have the habit of start my coding musings by branching away from other people's proposals.

In this case I found myself looking at this video, where the author codes the snake game in 4'30''

The video is very good and the code is purposefully and relentlessly hacky. And the game indeed works after that time. While I was looking at it I was thinking, wow, I cannot beat him at his own game, but is it really so much different between that

Rails Boilerplate Script

This is a quick and dirty script to get going with Rails

Assumptions:

  • Docker is installed
  • Docker Compose is installed
  • You will use postgres
  • You want omakase: rails default options (minitest, coffescript, turbolinks, actioncable...)
@oinak
oinak / es6_module_with_instances.js
Last active June 25, 2018 11:57
Factory Module pattern in modren js
window.Namespace = window.Namespace || {};
// Usage:
// Namespace.Rolenamee.init({ prop1: '.prop1', prop2: '.prop2' })
const Rolename = (function Rolename(expose) {
// private class/constructor
function Implementor({ foo, bar }) {
this.foo = $(foo); // store a value that will be needed asyncronously
$(bar).on("event", () => { // set up an asyncronous reaction
this.foo.method(); // use the stored value asyncronously through =>'s lexical `this`
@oinak
oinak / vanilaJQuery.js
Created April 22, 2018 22:10
JQuery to Vanilla js guide
// Element selection
document.querySelector('.someclass') // $('.someclass')[0]
document.querySelectorAll('.someclass') // $('.someclass')
// DOM manipulation
element.remove() // $element.remove()
element.prepend(otherElement) // $element.prepend(otherElement)
element.before(otherElement) // $element.before(otherElement)
element.classList.add('some') // $element.addClass('some')
element.classList.remove('some') // $element.removeClass('some')
@oinak
oinak / superclass_keyword_argument.rb
Last active November 23, 2017 11:46
how to initialize a keyword argument from the superclass (useful for dependency injection)
# http://ruby-doc.org/core-2.4.0/doc/syntax/calling_methods_rdoc.html#label-Hash+to+Keyword+Arguments+Conversion
class Super
attr_reader :shared
# ServiceObject style class-level activation method
def self.run(**args)
new(**args).tap{ |obj| obj.run }
end
def initialize(shared: 'All subclasses see me', **args)