Skip to content

Instantly share code, notes, and snippets.

ActiveAdmin::Dashboards.build do
# Add this section in your dashboard...
section "Background Jobs" do
now = Time.now.getgm
ul do
li do
jobs = Delayed::Job.where('failed_at is not null').count(:id)
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red'
end
@nunosilva800
nunosilva800 / 0_reuse_code.js
Created November 2, 2013 14:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nunosilva800
nunosilva800 / rails_helper.rb
Created June 28, 2014 14:10
expected to respond to `has_db_column?` - rails helper config
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'foreigner-matcher'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc, in
@nunosilva800
nunosilva800 / spec_helper.rb
Created June 28, 2014 14:10
expected to respond to `has_db_column?` - spec helper config
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs
@nunosilva800
nunosilva800 / delete_remotes_in_master.sh
Last active August 29, 2015 14:05 — forked from schacon/gist:942899
Delete remote branches merged into master
$ git remote prune origin |
git branch -r --merged origin/master |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
cut -d"/" -f2- |
xargs git push origin --delete
@nunosilva800
nunosilva800 / uri_field.rb
Created November 4, 2014 20:29
ensure uri fields have a valid protocol. HTTP by default
module Concerns::URIField
extend ActiveSupport::Concern
included do
def self.ensure_valid_protocol_in_uri(field, default_protocol = "http", protocols_matcher="https?")
define_method "#{field}=" do |new_uri|
if new_uri.present? and not new_uri =~ /^#{protocols_matcher}:\/\//
new_uri = "#{default_protocol}://#{new_uri}"
end
super(new_uri)
@nunosilva800
nunosilva800 / dup_ids.js
Created November 6, 2014 18:52
Jquery snippet to find duplicated IDs in DOM.
$('[id]').each(function(){
var ids = $('[id="'+this.id+'"]');
if(ids.length>1 && ids[0]==this)
console.warn('ID #'+this.id+' found '+ids.length+' times');
});
@nunosilva800
nunosilva800 / fixtures.rake
Created December 5, 2014 23:28
Comfy Sofa export and import fixtures to S3
namespace :fixtures do
namespace :s3 do
require 'fileutils'
def cms_export from, to
# create the fixtures files from DB
ComfortableMexicanSofa::Fixture::Exporter.new(from, to).export!
# get the bucket
bucket = AWS::S3.new.buckets[ENV['S3_BUCKET_FIXTURES']]
@nunosilva800
nunosilva800 / git_delete_merged.sh
Last active July 6, 2018 13:30
cleaning git repo
# To delete all branches that are already merged into the currently checked out branch:
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
echo "* Updating system"
sudo apt-get update
sudo apt-get -y upgrade
echo "* Installing packages"
sudo apt-get -y install build-essential libxml2-dev libxslt1-dev git-core nginx redis-server postgresql-client libpq5 libpq-dev curl nodejs htop
sudo locale-gen pt_PT.UTF-8
sudo dpkg-reconfigure locales
echo "* Installing rvm"