This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# post_serializer.rb | |
class PostSerializer < ActiveModel::Serializer | |
has_many :comments | |
attributes :id, :title, :content | |
end | |
# comment_serializer.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Renames subtitles files according to tv shows names found in a directory | |
# Acceped syntaxes for season/episode are: 304, s3e04, s03e04, 3x04, Ep-04 (case insensitive) | |
# | |
# Installation: | |
# Put this gist somewhere in your $PATH, like /usr/local/bin/sub.sh | |
# Chmod +x it | |
# cd ~/YourTvShowsFolderContainingVideoAndSubtitleFiles | |
# sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
begin | |
env = File.read(File.expand_path('~/projects/workable/.env')) | |
env_sample = File.read(File.expand_path('~/projects/workable/.env_sample')) | |
env_keys = env | |
.split("\n") | |
.reject { |e| e.start_with?('#') } | |
.map { |e| e.split('=')[0] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export YELLOW="\033[0;33m" | |
export NC="\033[0m" # No Color | |
# Until I figure out how to set the branch via argument, I have to edit this line | |
export SOURCE_DIR=~/projects/workable | |
export TARGET_DIR=~/projects/docker/workable | |
export BRANCH=research/docker | |
export DOCKER_TAG=latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find a pair of elements from an array whose sum equals a given number | |
# | |
# * The array contains only integers | |
# * The array can have duplicates | |
# * Return a boolean that indicates if the list has such a pair | |
# * We will start with an ordered (ascending order) list example | |
require 'benchmark/ips' | |
require 'set' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :benchmarks do | |
desc 'With cache' | |
task cache: :environment do | |
class RakeActionView < ActionView::Base | |
include Rails.application.routes.url_helpers | |
include ::ApplicationHelper | |
def default_url_options | |
{ host: 'localhost:3000' } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Rails.env.development? | |
require 'active_record/connection_adapters/postgresql_adapter' | |
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | |
def __explain_analyze(sql, command, *args) | |
meth = "#{command}_without_explain_analyze".to_sym | |
if /\A\s*SELECT/i.match(sql) | |
newsql = "EXPLAIN ANALYZE #{sql}" | |
plan = send(meth, newsql, *args).map { |row| row['QUERY PLAN'] }.join("\n") | |
Rails.logger.debug("\e[1m\e[31mQUERY PLAN FOR: #{sql.strip};\n#{plan}\e[0m") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function ($) { | |
$.extend({ | |
form: function (url, data, method) { | |
if (method == null) method = 'POST'; | |
if (data == null) data = {}; | |
var form = $('<form>').attr({ | |
method: method, | |
action: url, | |
}).css({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/middleware/subdomain_enforcer.rb | |
class SubdomainEnforcer | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
@request = Rack::Request.new(env) | |
if @request.params['sbd'].present? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
djs.each do |dj| | |
begin | |
dj.invoke_job | |
# h = YAML.load(dj.handler) | |
# puts "Processed dj #{dj.id}" | |
dj.destroy | |
'' | |
rescue => e | |
# ha = YAML.load(dj.handler) | |
puts "dj_id: #{dj.id}" |