Skip to content

Instantly share code, notes, and snippets.

@eljojo
eljojo / http_client.rb
Created July 5, 2013 08:40
simple ruby http client that allows you to use :TLSv1, for old servers that fail with OpenSSL 1.0.1e. https://raw.github.com/eljojo/polar_express/master/lib/polar_express/http_client.rb
class HTTPClient
attr_accessor :old_tls, :use_ssl
def initialize(opts = {})
config = {
old_tls: true,
use_ssl: nil,
}.merge(opts)
@old_tls = config[:old_tls]
@eljojo
eljojo / humanize_seconds.rb
Created June 24, 2013 14:15
How to generate a human readable time range using ruby on rails
# modification of http://stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails
def humanize_seconds secs, precision = 2
return unless secs
units = [[60, :second], [60, :minute], [24, :hour], [1000, :day]]
diffs = units.map do |count, name|
next if units.find_index([count, name]) > precision
if secs > 0
secs, n = secs.divmod(count)
pluralize(n.to_i, name.to_s) if n > 0
end
@eljojo
eljojo / replacing.rb
Created April 9, 2013 17:53
Replacing backreferences in Regular Expressions with its matched content.
require 'pp'
text = 'and the day is 08/11/1993 of course'
regex = 'the (day) (.+) <date> of'
result = regex.dup
until (s ||= 0) >= result.length
break unless section = (/(\((?!\?)(?:[^\(]+?[^\\]\)))/).match(result, s)
matches = Regexp.new(result.gsub(/<.+?>/, '.+?')).match(text)
offset = section.offset(0)
@eljojo
eljojo / application_helper.rb
Created March 26, 2013 18:50
random emoji application helper
module ApplicationHelper
# hand picked from http://www.grumdrig.com/emoji-list/
RANDOM_EMOJI = %w{&#x1f6b3; &#x1f3ca; &#x1f355; &#x1f354; &#x1f35f; &#x1f33d; &#x1f349; &#x1f3a3; &#x1f385; &#x1f47b; &#x1f383; &#x1f40e; &#x1f434; &#x1f412; &#x1f435; &#x1f417; &#x1f437; &#x1f43b; &#x1f474; &#x1f640; &#x1f473; &#x1f46e; &#x1f472; &#x1f48f;}
def random_emoji(count = 5)
RANDOM_EMOJI.shuffle[0..count].join(' ')
end
end
@eljojo
eljojo / hash_manipulation.rb
Created December 8, 2015 19:41
some playing with functional programming and ruby
# A HashManipulation is a helper object.
# The idea is to aid when modifying hashes.
# changes = HashManipulation.new
# changes.key { |key| key.upcase }
# changes.value { |value| value.length }
# changes.("children" => [1, 2, 3]) # {"CHILDREN" => 3}
module Reports
class HashManipulation
def initialize
@key = -> (obj) { obj }
@eljojo
eljojo / .bash_profile
Created June 5, 2012 17:46
my bash ps1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/'
}
export PS1="\h:\W\$(parse_git_branch) \u\$ "
@eljojo
eljojo / media.js
Created January 28, 2012 23:45
javascript para buscar medios embebeables en una url
/**
* media.js
* script para buscar medios embebeables en una url
* por josé tomás albornoz - www.eljojo.net
* usa trozos de código sacados de: https://twimg0-a.akamaihd.net/b/1/bundle/t1-more-en-201201121558.js
*/
var mediajs = {
providers: {
youtube:{
@eljojo
eljojo / growth_hacking.md
Last active August 29, 2015 14:22
Growth Hacking

I know about the existence of Growth Hacking and I know that as a StartUp one of your goals is to, well, grow as much as possible.
I also know about the existence of promotional posts, and how they can benefit both writers and companies looking to reach audiences.
What I didn't know, is how low some companies can go in order to promote their business for free.
Without further ado, here's an email I got yesterday. Let it speak by itself.

Hi Jose Tomas,

We’d love to see what tips you have for social media marketers. 

We would like you to create a post on your personal blog where you share

<html>
<head>
<title>This is the title</title>
<link rel="stylesheet" href="http://railsgirls.com/assets/bootstrap.css">
<link rel="stylesheet" href="http://railsgirls.com/assets/bootstrap-theme.css">
</head>
<body>
<h1>Hello HTML!</h1>
<p>How's it going?</p>
<form action="/add_to_list" method="get">
@eljojo
eljojo / gist:be8a0feff34b4d02509b
Created May 4, 2015 17:38
dokku_on_debian_after_fixing_nginx
root@dokku:~/dokku# make install
apt-get update
Hit http://security.debian.org jessie/updates InRelease
Hit http://ftp.de.debian.org jessie InRelease
Hit http://security.debian.org jessie/updates/main Sources
Hit http://ftp.de.debian.org jessie-updates InRelease
Hit http://security.debian.org jessie/updates/main amd64 Packages
Hit http://ftp.de.debian.org jessie/main Sources
Hit http://security.debian.org jessie/updates/main Translation-en
Hit http://ftp.de.debian.org jessie/main amd64 Packages