Skip to content

Instantly share code, notes, and snippets.

View lagartoflojo's full-sized avatar
🇨🇱
en 🇩🇪

Hernán Schmidt lagartoflojo

🇨🇱
en 🇩🇪
  • Nürnberg, Deutschland
View GitHub Profile
@lagartoflojo
lagartoflojo / deploy-fix.rb
Created April 15, 2011 01:15
Agregar al final de deploy.rb para arreglar problemas con deploy de capistrano en Windows.
on :start, "bundle:fix_gemfile"
namespace :bundle do
desc "Fix Gemfile.lock to use *nix gems"
task :fix_gemfile do
gem_file = File.read("Gemfile")
replace = gem_file.gsub(/(.*)gem (.*)win32(.*)\n/, "")
File.open("Gemfile", "w") {|file| file.puts replace}
gem_file_lock = File.read("Gemfile.lock")
@lagartoflojo
lagartoflojo / README.markdown
Created July 21, 2011 22:33
Win/Mac/Linux Compatible Capistrano Recipe for Students of your Rails Course

TODO

  • Include basic Gemfile
  • Include Apache config
  • Specify available tasks
  • How to setup the students' PCs

Introduction

When giving a course based on Ruby on Rails, you will have many students coming from different backgrounds, using different Operating Systems, so you want their experience to be as smooth as possible. Deploying applications to the class server can be a pain in other frameworks, but in Rails, using Capistrano and Bundler, it is actually quite easy. This deploy configuration file for Capistrano intends to be as compatible with different OSs, as easy to use, and as complete as possible.

@lagartoflojo
lagartoflojo / Bio.markdown
Created August 24, 2011 19:12
Bio para Ataxic

Hernán empezó a los 16 años a crear sus propias páginas web para entretenerse y por trabajo. En ese entonces, Geocities y Tripod la llevaban, toda página debía tener una intro en Flash (si tenía sonido, mejor aún), y todo webmaster que se respetara diseñaba para Internet Explorer 4.0.

Una vez en la universidad, Hernán descubrió, en su temprana versión 1.2, la plataforma Ruby on Rails para la rápida creación de aplicaciones web, y ha dedicado una gran parte de su tiempo libre en perfeccionarse en su uso. Desde entonces, ha desarrollado sitios para tiendas de música (Billboard.cl y Musicland.cl), para una empresa de telecomunicaciones (GTD Manquehue), para una startup (Agendy.com), y para una empresa de asesoría en innovación e incubadora (DictUC).

Actualmente, Hernán está elaborando su memoria, en la cual aplica las últimas tecnologías web en crear una aplicación para el ámbito de la educación y diseñada para dispositivos móviles.

@lagartoflojo
lagartoflojo / tresleches.md
Last active December 19, 2015 03:58
Receta de Torta Tres Leches

Torta Tres Leches

Bizcochuelo

  • 4 huevos separados
  • 1 1/2 taza de harina
  • 1 1/4 taza de azúcar
  • 4 cucharaditas de esencia de vainilla
  • 3 cucharaditas de polvos de hornear
Ember.Handlebars.helper 'format', (body) ->
body = Handlebars.Utils.escapeExpression(body)
body = body.replace(/\n\r?/g, '<br>')
new Handlebars.SafeString(body)
# Usage: {{format stringWithNewLines}}
@lagartoflojo
lagartoflojo / try-and-allow.md
Last active September 26, 2016 11:28
How to get your butt bitten by Rails' try and rspec's allow(x).to receive(:bla)

Why Rails' try() and rspec's allow(x).to receive(:bla) can bite you in the butt:

When actions are taken by superusers, we're supposed to append admin_ to the SystemLog event names. For example: when one of us logs in, there should be a SystemLog with admin_log_in event. When normal users log in, there's a SystemLog with log_in event.

If you check your SystemLog table, you'll see that's not currently true ;) And it hasn't been for quite a while. This is surprising, since all of our SystemLog specs are passing!

Digging deeper, we find self.prefixed_event_name(event_name) in SystemLog, which is supposed to add the admin_ prefix. That method checks if the current_user is an admin with: current_user.try(:admin?). current_user could be nil, which is why we use try here. But guess what: the method User#admin? does not exist! We recently renamed admins to superusers, so the correct call should be current_user.try(:superuser?).

But then, how can our tests be passing??

@lagartoflojo
lagartoflojo / service.rb
Created August 21, 2017 20:17
Dependency Injection example in Ruby
require 'resolv'
class ConferenceDomainsService
def initialize(conference, resolver = Resolv::DNS.new)
@conference = conference
@resolver = resolver
end
##
# Checks if domain correctly points to the hosted version
@lagartoflojo
lagartoflojo / copy-k8s-resources-across-namespaces.sh
Last active October 30, 2017 16:48 — forked from simonswine/copy-k8s-resources-across-namespaces.sh
Copying kubernetes resources accross namespaces
kubectl get rs,secrets -o json --namespace <OLD_NAMESPACE> | jq '.items[].metadata.namespace = "<NEW_NAMESPACE>"' | kubectl create -f -
@lagartoflojo
lagartoflojo / rest-vs-graphql.md
Created December 13, 2016 11:10
REST vs. GraphQL - the problems with REST and how GraphQL aims to solve them

TL;DR: REST endpoints cause latency and bandwidth problems. GraphQL aims to solve those issues. At the SCC, we'd like to create a prototype of a GraphQL API.

REST

For a good number of years now, REST (Representational state transfer) has been the most common way of writing web APIs. While there is no "REST standard", the basic idea is that web servers provide access to resources through unique URLs, and those resources can provide hypertext links to other related resources.

REST example

For example, we could access the user David (the resource) through the URL http://example.com/users/david. We can operate on that resource by using the HTTP verbs GET, POST, PUT, DELETE, etc. To retrieve the resource's data, we can request GET http://example.com/users/david, and receive some JSON, XML or HTML data structure with David's information in return. In that structure, we might find a link the David's friends at `http://example.com/users/