Skip to content

Instantly share code, notes, and snippets.

@agarie
agarie / create-posts-from-csv.rb
Created Dec 10, 2021
This script receives (from a filename argument or stdin) a CSV, with headers, containing columns post_title, post_date and post_content and converts each entry into a markdown post with Liquid front matter.
View create-posts-from-csv.rb
#!/usr/bin/env ruby
# Convert the entries from a CSV with headers
# - post_title
# - post_date (must include year-month-day)
# - post_content
# into markdown posts with Liquid's front matter and the correct naming
# structure. Reminder that valid HTML posts are also valid markdown.
require "csv"
@agarie
agarie / parse_wp_exported_posts_backup.rb
Created Dec 6, 2021
A script to convert the posts from a WordPress SQL backup into a CSV for easier handling with other tools. Important comment: "Typical reminder to not write a parser half drunk at 3AM".
View parse_wp_exported_posts_backup.rb
# Parse a SQL file exported from a WordPress site containing the posts backup,
# generally named `wphf_posts.sql`, and create a file `wphf_posts.sql.csv`
# containing the data in CSV format.
#
# I could've used a proper sql parser but was in the mood to write some shitty code lol
require 'csv'
WP_POSTS_SQL_FILE = ARGV[0]
WP_POSTS_CSV_FILE = WP_POSTS_SQL_FILE + ".csv"
@agarie
agarie / download-conf-papers.rb
Last active Dec 12, 2017
Quick script I made to download papers from NIPS. The subjects are specified in `SUBJECTS_RE`.
View download-conf-papers.rb
require 'fileutils'
require 'nokogiri'
require 'open-uri'
require 'pp'
require 'typhoeus'
SUBJECTS_RE = /deep|deeply|neural|convolutional|network|recurrent|lstm|object recognition|object classification|object detection|image classification/
def paper_list_url(issue)
"https://papers.nips.cc/book/advances-in-neural-information-processing-systems-#{issue}-#{1987 + issue}"
@agarie
agarie / rgb2cmyk.sh
Created Jan 20, 2017
Convert the colors of a PDF file from RGB to CMYK for printing.
View rgb2cmyk.sh
#!/usr/bin/zsh
gs -dSAFER -dBATCH \
-dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-dProcessColorModel=/DeviceCMYK \
-sOutputFile=$2 \
$1
@agarie
agarie / faces_dataset_32x30.list
Last active Nov 19, 2015
Code used to convert the PGM images from the dataset used in one of Tom Mitchell's homework assignments (https://www.cs.cmu.edu/~tom/faces.html) to CSV files.
View faces_dataset_32x30.list
./faces/kawamura/kawamura_straight_happy_open_4.pgm
./faces/phoebe/phoebe_up_sad_open_4.pgm
./faces/saavik/saavik_left_sad_sunglasses_4.pgm
./faces/sz24/sz24_right_angry_open_4.pgm
./faces/tammo/tammo_left_angry_sunglasses_4.pgm
./faces/bpm/bpm_up_neutral_open_4.pgm
./faces/kawamura/kawamura_up_angry_open_4.pgm
./faces/choon/choon_right_happy_sunglasses_4.pgm
./faces/saavik/saavik_right_sad_sunglasses_4.pgm
./faces/ch4f/ch4f_straight_angry_open_4.pgm
@agarie
agarie / tmux.md
Last active Feb 27, 2021
tmux cheatsheet
View tmux.md
@agarie
agarie / A evolução de uma arquitetura distribuída.md
Created Jul 2, 2015
Algumas anotações feitas durante a RuPy Campinas 2015.
View A evolução de uma arquitetura distribuída.md

Autor: Guilherme Garnier

  • globo.com

  • Plataforma de vídeos: requisições pra diabo + vídeos pra diabo

  • Monolito: projeto Rails imenso blabla, eventualmente fodeu tudo para manter

  • Vários pontos interessantes

  • Circuit Breaker: ver gem; ver post do Martin Fowler

  • github: cap_blue_green_deploy

@agarie
agarie / xmonad.md
Last active Sep 23, 2021
XMonad cheatsheet, resources, etc.
View xmonad.md

xmonad

Shortcuts

  • Mod + Shift + Enter -> Open console
  • Mod + Space -> Change tiling mode
  • Mod + j & Mod + k -> Move focus between windows
  • Mod + Shift + c -> Close the focused window
  • Mod + . & Mod + , -> Control the number of windows displayed in the master pane on the left
  • Mod + Enter -> Move the focused window to the master pane on the left
@agarie
agarie / rng.lua
Created Jun 12, 2015
RNGs for some distributions written in Lua, mostly as a first exercise in the language.
View rng.lua
-- Some RNGs for getting to play with Lua.
--
-- Carlos Agarie <carlos@onox.com.br>
--
-- Public domain.
-- N(mean; std^2).
function gauss(mean, std)
if std <= 0.0 then error("standard deviation must be positive!") end
@agarie
agarie / create_has_library.rb
Created May 23, 2015
A function for inquiring if a library is available. Automatically requires the library if it is available.
View create_has_library.rb
# Create a method `has_<library>?` on Module that requires the library and
# return a boolean indicating if the library is available.
#
# @param library [String] The library name.
# @return [Boolean] Whether the library is available or not.
def create_has_library(library) #:nodoc:
define_singleton_method("has_#{library}?") do
cv = "@@#{library}"
unless class_variable_defined? cv
begin