Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / slack.css
Last active February 12, 2016 12:28
Stylish for slack
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("slack.com") {
.bot_message {
font-size:12px;
color: #CCC;
}
.bot_message .member_image {
height: 16px;
{
"browser" : true,
"jquery" : true,
"devel" : true,
"curly" : true,
"latedef" : true,
"maxdepth" : 3,
"newcap" : true,
"noarg" : true,
"noempty" : true,
@brenes
brenes / instructions
Created June 8, 2015 09:34
Repairing non-monotic index git error
> git fetch
...
error: non-monotonic index .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.idx
...
> rm .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.idx
> git index-pack .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.pack
@brenes
brenes / custom_mini_profiler.rb
Last active August 29, 2015 14:21
Utility class for decorating a method and adding the information to the rach mini profiler summary
# Simple class to decorate a method and send information MiniProfiler
# Usage: CustomMiniProfiler.measure MyClass, :mymethod, "This method takes..."
class CustomMiniProfiler
def self.measure klass, method, message, class_method=false
receptor_class = class_method ? klass.singleton_class : klass
receptor_class.send :define_method, "#{method}_with_mini_profiler" do |*args, &block|
Rack::MiniProfiler.step(message) do
send "#{method}_without_mini_profiler", *args, &block
end
@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 / 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 {
@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 / 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 / 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