Skip to content

Instantly share code, notes, and snippets.

View agarie's full-sized avatar

Carlos Agarie agarie

View GitHub Profile
@agarie
agarie / create-posts-from-csv.rb
Created December 10, 2021 20:05
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.
#!/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 December 6, 2021 17:47
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".
# 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 December 12, 2017 02:36
Quick script I made to download papers from NIPS. The subjects are specified in `SUBJECTS_RE`.
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 January 20, 2017 18:59
Convert the colors of a PDF file from RGB to CMYK for printing.
#!/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 November 19, 2015 17:58
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.
./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 / xmonad.md
Last active September 23, 2021 09:05
XMonad cheatsheet, resources, etc.

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 June 12, 2015 00:38
RNGs for some distributions written in Lua, mostly as a first exercise in the language.
-- 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 04:08
A function for inquiring if a library is available. Automatically requires the library if it is available.
# 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
@agarie
agarie / ngrams.rb
Created April 14, 2015 18:19
Generate {uni,bi,tri}grams from a token list.
class Counter
def initialize
@counts = Hash.new 0
end
def <<(key)
@counts[key] += 1
end
end
@agarie
agarie / icc.js
Created November 6, 2014 18:04
Item Characteristic Curve plotting with d3js.
var N = 100,
a = 2.0,
b = 0.0,
c = 0.2;
var defaultScale = { mu: 0, sigma: 1 },
enemScale = { mu: 500, sigma: 100 };
// @return: The probability of hit at `theta`, or P(right | theta, a, b, c).
var prob = function (a, b, c, theta) {
return c + (1 - c) / (1 + Math.exp(- a * (theta - b)));