Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / multi-scp-copy
Created June 15, 2014 16:26
Copying various files through scp, one connection at a time
for filename in *; do
scp "$filename" user@host:/folder;
done
@brenes
brenes / gist:b59b0a77fd397290d9f7
Created October 1, 2014 13:49
Averiguar IP pública
curl ipecho.net/plain
@brenes
brenes / fix-srt.rb
Last active June 8, 2018 07:47
Small script for fixing srt files with blank lines
# This small script uses the 'srt' gem to parse the srt file
# It solves problems with certain subtitle files with empty lines that make Flex crash
# You can use it with files, folders with files or even folders with subfolders with files (God bless Recursivity)
# USAGE: ruby fix-srt.rb file/to/fix.srt
# USAGE: ruby fix-srt.rb folder/with/files/to/fix
# USAGE: ruby fix-srt.rb folders/with/subfolders/to/fix
require 'rubygems'
require 'srt'
class StrFixer
@brenes
brenes / gist:c556ed0d0070e27444b5
Last active August 29, 2015 14:09
extending objects through modules
class A
def to_s
"a"
end
end
module B
def to_s
super + "b"
end
@brenes
brenes / gist:bfaf3aad4d456e9063a0
Created November 25, 2014 08:50
Installing ruby stuff on Debian Jessie
* First: Install libxml2 through RVM
rvm pkg install libxml2
* Then: Configure libxml in bundle
bundle config build.libxml-ruby \
--with-xml2-lib=${HOME}/.rvm/usr/lib \
--with-xml2-include=${HOME}/.rvm/usr/include/libxml2
@brenes
brenes / error_redirection.rb
Created December 9, 2014 16:29
Rack error redirector
# This rack engine redirects to external URLs when some error is thrown.
# How to use it?
# Just add the rack middleware in config/application.rb
# require 'rack/error_redirection'
# config.app_middleware.insert_before('ActionDispatch::ShowExceptions', 'Rack::ErrorRedirection')
# And fill the error_404_url and error500_url variables
module Rack
class ErrorRedirection
def initialize(app)
@app = app
@brenes
brenes / proc.rb
Last active August 29, 2015 14:14 — forked from qrush/proc.rb
# somewhere in your middleware stack...
# request.env['yourapp.someid'] = "1337"
YourApp::Application.configure do
config.log_tags = [
-> request {
request.env['yourapp.someid']
}
]
end
@brenes
brenes / twitter.css
Created April 30, 2015 10:09
Stylish Stylesheet for twitter
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("twitter.com") {
# Hiding left sidebar
.dashboard.dashboard-left {
display: none !important;
}
# Wider timeline
#timeline {
# This set of classes implement the algorithm described in
# > Jia, T., & Barabási, A. L. (2013).
# > Control capacity and a random sampling method in exploring controllability of complex networks.
# > Scientific reports, 3.
#
# This algorithm obtains a score for each node of a network telling how 'driver' it is
# i.e. What is the chance this node is in a set of nodes that can control the whole network
#
# Look at the test files to see how to run this algorithm
#
@brenes
brenes / application_controller.rb
Last active August 29, 2015 14:21 — forked from scottwb/application_controller.rb
How to get filters from a Controller
# Add these methods to your ApplicationController. Then, any controller
# that inherits from it will have these methods and can programmatically
# determine what filters it has set.
class ApplicationController < ActionController::Base
def self.filters(kind = :around)
_process_action_callbacks.select{|f| f.kind == kind}.map(&:filter)
end
def self.before_filters