Skip to content

Instantly share code, notes, and snippets.

@rogerleite
rogerleite / install_monaco_font.sh
Last active Sep 29, 2022
Install Monaco font in Linux
View install_monaco_font.sh
#!/bin/bash
# Install Monaco font in Linux
# Version from nullvideo https://gist.github.com/rogerleite/99819#gistcomment-2799386
sudo mkdir -p /usr/share/fonts/truetype/ttf-monaco && \
sudo wget https://gist.github.com/rogerleite/b50866eb7f7b5950da01ae8927c5bd61/raw/862b6c9437f534d5899e4e68d60f9bf22f356312/mfont.ttf -O - > \
/usr/share/fonts/truetype/ttf-monaco/Monaco_Linux.ttf && \
sudo fc-cache
@rogerleite
rogerleite / _install.md
Last active Sep 2, 2022
Some scripts to install things
View _install.md

Introduction

Some install scripts. Target to work with Ubuntu 12 or greater.

Table of Scripts

@rogerleite
rogerleite / nginx.conf
Created Aug 2, 2012
Configuração Nginx
View nginx.conf
user www-data;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
@rogerleite
rogerleite / PlainEnglish.livemd
Created Apr 30, 2021
Interpret and evaluate arithmetic expressions written in plain English (Livebook Elixir)
View PlainEnglish.livemd

Arithmetic expressions in plain English

Interpret and evaluate arithmetic expressions written in plain English

Example: "one plus two times four"

  • numbers are [zero-ten]
  • numbers can be negative, for example: "negative five"
  • "plus" and "times" are the only supported operations natural order of operations apply, multiply before add.
  • "negative" is optional string before the number and is not an operation "one minus two" is expressed as "one plus negative two"
@rogerleite
rogerleite / defensive-ruby.rb
Created Jun 12, 2019
Example of defensive ruby
View defensive-ruby.rb
# example 1: adopting default values and trying to not break things
def adapter(action)
action = action.to_sym unless action.is_a?(Symbol)
batch = {
active_products: "ProductsActive",
inactive_products: "ProductsInactive",
download_products: "ProductsDownload"
}
batch.fetch(action, "UnknownAction")
end
@rogerleite
rogerleite / converters.rb
Last active Sep 17, 2018
Ruby and CSV examples
View converters.rb
require "csv"
require "date"
puts CSV::HeaderConverters.keys.inspect # => [:downcase, :symbol]
# Add new header converter
CSV::HeaderConverters[:remap] = lambda do |raw_value|
raw_value = raw_value.to_sym
case raw_value
when :country
@rogerleite
rogerleite / backup_redmine_with_mutt
Created Feb 16, 2009
Exemplo de script que faz backup do Redmine
View backup_redmine_with_mutt
#ARQUIVO: bkp_redmine.sh
#!/bin/sh
BACKUP_FOLDER=/home/minha_empresa/backup/redmine
DATE_BACKUP=`date +%Y%m%d`
DB_FILE_BKP="$BACKUP_FOLDER"/"$DATE_BACKUP"_redmine_db.gz
FILES_FOLDER_BKP="$BACKUP_FOLDER"/files
FILES_FILE_BKP="$BACKUP_FOLDER"/"$DATE_BACKUP"_redmine_files.gz
@rogerleite
rogerleite / oracle_export.rb
Created Oct 24, 2009
Access Oracle with jruby using JDBC. Export data to json format.
View oracle_export.rb
=begin
Requisitos Minimos para rodar este script:
#jruby 1.1 ou superior (nao testei com superior :D)
apt-get install jruby
#baixar o oracle jdbc (para o 10g, ou procure a versão que deseje) de:
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.html
#copiar o ojdbc14.jar para (usar sudo):
@rogerleite
rogerleite / test.sh
Created Jun 26, 2013
Using Shell Script to test your server
View test.sh
#!/bin/bash
URL=http://localhost:8080
## Unit-Testable Shell Scripts (http://eradman.com/posts/ut-shell-scripts.html)
typeset -i tests_run=0
function try { this="$1"; }
trap 'printf "$0: exit code $? on line $LINENO\nFAIL: $this\n"; exit 1' ERR
function assert {
let tests_run+=1