Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / application.html.erb
Created November 20, 2017 08:33 — forked from Dagnan/application.html.erb
Inline CSS or JS in Rails 5
<!DOCTYPE html>
<html>
<head>
<%= inline_js 'application.js' %>
<%= inline_css 'application.css' %>
</head>
<body>
</body>
</html>
@brenes
brenes / character_set_and_collation.rb
Created June 23, 2016 13:33 — forked from tjh/character_set_and_collation.rb
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@brenes
brenes / xargs.md
Created April 14, 2016 10:46 — forked from porras/xargs.md

This is my best try at transcribing of the lightning talk I gave at RUG::B on April 2016. Due to poor time management (LOL) the delivery was rushed and some examples were skipped, I hope having them posted here makes them more useful.

xargs

xargs is a small but very useful program that is installed in most if not all of your computers¹. Many of you probably know it. Those who don't will learn something really useful, but those who do will learn a couple of cool tricks, too.

Why xargs

You might have heard about the Unix philosophy:

@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
# 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 / 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 / 1ST README
Last active December 11, 2015 21:39 — forked from rsierra/1ST README.md
Rails 2.3.5 version of the Rails 2.1.1 patch by @rsierra
Rails 2.3.5 patch for CVE-2013-0333 vulnerability:
If you can't upgrade your Rails installation you can get the OkJson parser and include it in your project. How?
- Add cve_2013_0333_patch.rb in '/config/initializers' directory.
- Add okjson.rb in '/lib/active_support/json/backends' directory.
To test the parser, try to decode with a bad formatted json:
(I don't know if it's the best test, but you check if you are using the json parser in the rails 2.3 official patch)
@brenes
brenes / index.html
Created February 8, 2012 19:16 — forked from enjalot/index.html
Simple Pie Chart example with D3.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Testing Pie Chart</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<style type="text/css">
@brenes
brenes / rawclone_bundler.rb
Created February 8, 2012 12:21 — forked from rsierra/rawclone_bundler.rb
Script para generar el Gemfile de bundler a partir de un 'gem list'
#!/usr/bin/env ruby
# So you want to start developing an already "woking" project. No
# bundle, config.gem's not present or messing up dependencies. Fear
# not!
# Do a "gem list" wherever the project is already working
# (production?, some colleage machine?). Make a file with this format:
#
# chronic (0.2.3)
# colored (1.1)
@brenes
brenes / .gitignore
Created January 29, 2012 23:33 — forked from karmi/.gitignore
Simple ping:pong WebSockets server and client in Ruby (em-http and em-websocket
Gemfile.lock