Skip to content

Instantly share code, notes, and snippets.

Avatar
👊
Working!

Aitor García Rey aitor

👊
Working!
View GitHub Profile
@aitor
aitor / README.md
Created Oct 13, 2019 — forked from igorwwwwwwwwwwwwwwwwwwww/README.md
clickhouse-playground
View README.md

clickhouse-playground

capture logs:

heroku logs --tail -a travis-api-production | grep at=info | gsed -e 's/^\([0-9]*-[0-9]*-[0-9]*\)T\([0-9]*:[0-9]*:[0-9]*\)/date=\1 time="\1 \2" /' | lcut date time method path host request_id fwd dyno connect service status bytes > access.log

boot:

View taxid_validator.rb
# frozen_string_literal: true
class TaxidValidator < ActiveModel::EachValidator
VALID_FORMATS = {
nif: /^(\d{8})([A-Z])$/,
nie: /^[XYZ]\d{7,8}[A-Z]$/,
}.freeze
CONTROL_DIGIT_TABLE = %w[T R W A G M Y F P D X B N J Z S Q V H L C K E].freeze
CONTROL_DIGIT_NIE_MAPPING = {
View ruby_hook.rb
# Trigger a travis build
post "/push-webhook" do
uri = URI.parse("https://api.travis-ci.org/repo/your-org/your-repo/requests")
request = Net::HTTP::Get.new(uri.request_uri)
request["Content-Type"] = "application/json"
request["Accept"] = "application/json"
request["Travis-API-Version"] = "3"
request["Authorization"] = "token your-token"
View env.java
private Environment(String ip, String mac, String iccid, String imei,
String carrier, String device, String os, String androidId,
String localization) {
this.ip = ip;
this.mac = mac;
this.iccid = iccid;
this.imei = imei;
this.carrier = carrier;
this.device = device;
this.os = os;
View heroku.sh
#!/usr/bin/env bash
set -ex
# Pass in Heroku API token
token=$1
# We run this script in a stateless Docker image, so to make the script a bit
# cleaner, we just write out the credentials to a file that the Heroku Toolbelt
# knows to read.
View run.sh
> pip2.7 install otpsecure  
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting otpsecure
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python2.7/site-packages (from otpsecure) (4.8.0)
Requirement already satisfied: pycrypto>=2.6.1 in /usr/local/lib/python2.7/site-packages (from otpsecure) (2.6.1)
Requirement already satisfied: requests>=2.4.1 in /usr/local/lib/python2.7/site-packages (from otpsecure) (2.22.0)
Requirement already satisfied: soupsieve>=1.2 in /usr/local/lib/python2.7/site-packages (from beautifulsoup4->otpsecure) (1.9.2)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python2.7/sit
@aitor
aitor / authenticate_user_spec.rb
Last active Jul 23, 2019
Service / Usecase Objects in vanilla Ruby
View authenticate_user_spec.rb
describe AuthenticateManagerService do
subject(:context) { described_class.call(username, password) }
describe '.call' do
context 'when the context is successful' do
let(:username) { 'correct_user' }
let(:password) { 'magic' }
it 'succeeds' do
expect(context).to be_success
View lipp-button.js
// Source at https://developer.paypal.com/js/pages/docs/integration/direct/identity/lipp-button.js
//...
function _getConfig() {
var confObj = {};
var builders = buildForm.querySelectorAll('input, select');
var i = 0;
var el;
@aitor
aitor / asdf_elixir.sh
Created Dec 31, 2018
POWERLEVEL9K custom elixir/erlang prompt segment
View asdf_elixir.sh
POWERLEVEL9K_ELIXIR_ICON=$'\ue62d'
prompt_asdf_elixir() {
if [ $commands[asdf] ]; then
ELIXIR_ICON=$'\ue62d'
local asdf_global_conf="$HOME/.tool-versions"
local version_regex="s/^\([.0-9]*\).*/\1/p"
local config_regex="s/.*(set by \(.*\))/\1/p"
local elixir_current="$(asdf current elixir)"
local elixir_current_version="$(echo $elixir_current | sed -n $version_regex)"
View 20160307172445_change_paperclip_attachment_path.rb
class MoveAttachmentsToNewLocation < ActiveRecord::Migration
def initialize(name = self.class.name, version = nil)
access_key = Rails.application.secrets.g3_access_key_id
secret_key = Rails.application.secrets.g3_secret_access_key
storage = Fog::Storage::Google.new google_storage_access_key_id: access_key,
google_storage_secret_access_key: secret_key
@bucket_name = Rails.application.secrets.g3_bucket
@bucket = storage.directories.get(@bucket_name)
super(name, version)