Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Antonio Alberto Lobato tomlobato

🎯
Focusing
Block or report user

Report or block tomlobato

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomlobato
tomlobato / gist:71e2815ff210dc24a1717df2afd8048a
Last active Jul 7, 2019 — forked from nevans/gist:9374041
simple ruby console histogram generator
View gist:71e2815ff210dc24a1717df2afd8048a
require 'pry' # gem install pry
# Pass in an enumeration of data and
# (optionally) a block to extract the grouping aspect of the data.
#
# Optional: sort_by lambda (operates on group key and count)
def puts_hist(data, sort_by:nil, &blk)
data = data.map(&blk) if blk
counts = data.each_with_object(Hash.new(0)) {|k,h| h[k]+=1}
@tomlobato
tomlobato / benchmark_results.rb
Last active Mar 10, 2018 — forked from havenwood/benchmark_results.rb
Benchmarking serialization speed of YAML, JSON, Marshal, and MessagePack in MRI
View benchmark_results.rb
# 2.4.2p198 on MBP 2017 i7
user system total real
-- YAML size=86 delta_vsz=0 delta_rss=2092
17.730000 0.060000 17.820000 ( 17.851288)
-- JSON size=83 delta_vsz=0 delta_rss=4
0.850000 0.000000 0.870000 ( 0.892370)
@tomlobato
tomlobato / throttle-and-debounce.sh
Created Feb 2, 2018 — forked from niieani/throttle-and-debounce.sh
throttle and debounce commands in bash
View throttle-and-debounce.sh
#!/usr/bin/env bash
declare -i last_called=0
declare -i throttle_by=2
@throttle() {
local -i now=$(date +%s)
if (($now - $last_called >= $throttle_by))
then
"$@"
@tomlobato
tomlobato / conf for rbenv and systemd symlink
Last active Jan 11, 2018
munin-plugins-rails-0.2.13 adjusts for passenger 5
View conf for rbenv and systemd symlink
@tomlobato
tomlobato / memory_layout.md
Created Aug 12, 2017 — forked from CMCDragonkai/memory_layout.md
Linux: Understanding the Memory Layout of Linux Executables
View memory_layout.md

Understanding the Memory Layout of Linux Executables

Required tools for playing around with memory:

  • hexdump
  • objdump
  • readelf
  • xxd
  • gcore
@tomlobato
tomlobato / update_wp.sh
Last active Apr 22, 2017
Update wordpress installations via cron
View update_wp.sh
#!/bin/bash
# /etc/crontab
# 0 8 * * * root update_blogs.sh >> /var/log/update_blogs.log
admin_mail=my@email.com
blogs=`ls -d /var/www/{blog1,blog2,blog3}`
update_wp(){
blog=$1
@tomlobato
tomlobato / EnumerableEnum.swift
Last active Feb 11, 2018
Swift 3 - Enum utils
View EnumerableEnum.swift
//
// Based on https://quinesoft.de/2016/05/23/swift-enumerate-iterate-enum/
//
// Usage:
//
// public enum Pies: Int, EnumerableEnum {
// case apple
// case strawberry
// case chicken
// }
@tomlobato
tomlobato / equal-validator.directive.ts
Last active Feb 18, 2017
Angular 2 equal-validator.directive.ts
View equal-validator.directive.ts
import { Directive, forwardRef, Attribute } from '@angular/core';
import { Validator, AbstractControl, NG_VALIDATORS } from '@angular/forms';
// variation from https://plnkr.co/edit/KgjSTj7VqbWMnRdYZdxM?p=preview
@Directive({
selector: '[validateEqual][formControlName],[validateEqual][formControl],[validateEqual][ngModel]',
providers: [
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => EqualValidator), multi: true }
]
@tomlobato
tomlobato / s3size.sh
Created Jan 24, 2016
Find Amazon S3 bucket usage
View s3size.sh
function s3size() {
for path in $*; do
size=$(aws s3 ls "s3://$path" --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{printf "%.2fGb\n", (total/1024/1024/1024)}');
echo "[s3://$path]=[$size]";
done;
}
@tomlobato
tomlobato / deploy.rb
Created Jan 24, 2016
Working deploy.rb for mina, on rails
View deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
task :deploy_prod => :environment do
set :rails_env, 'production'
set :restart_workers, true
set :branch, 'master'
set :deploy_to, '/path/to/PROD/rails/root'
set :test_url, "http://www.example.com"
You can’t perform that action at this time.