Skip to content

Instantly share code, notes, and snippets.

View abaez's full-sized avatar

Alejandro Baez abaez

View GitHub Profile
@abaez
abaez / 3digits.pl
Last active December 19, 2015 10:59
Converts digits from 00-99 or 0-9 to 000-099, of any files, in a directory tree.
#!/usr/bin/perl -w
use File::Copy;
use Cwd;
# a simple rename scheme for the files.
sub add0 {
move($_[0], "$_[1]$_[0]");
}
@abaez
abaez / fisher-yates_shuffle.lua
Created October 30, 2013 16:33
randomize an order of an array.
#!/usr/bin/env lua
function shuffle(tab)
-- allocation of the random array
local random_tab = {}
for i=1,#tab do
table.insert(random_tab, nil)
end
@abaez
abaez / screen_details.lua
Last active December 29, 2015 05:39
Find the ppi, area, and dimensions of a screen.
#!/usr/bin/env lua
--- returns the ppi from the resolution and diagonical inches of the screen.
-- @func ppi
-- @param inch is the diagonal inches of screen.
-- @param width is the width of native resolution.
-- @param height is the height of native resolution.
function ppi(inch, width, height)
return math.sqrt(width^2 + height^2) / inch -- ppi = pixels/inch
end
@abaez
abaez / exist.lua
Last active January 3, 2016 13:09
checks if a value exists in a table
--- checks if a value exist in a table.
-- @function exist
-- @param t a table to check.
-- @param w a value to look for.
function exist(t, w)
for _, v in ipairs(t) do
if v == w then
return true
end
end
@abaez
abaez / memoize_fn.lua
Created January 28, 2014 19:07
memoize function example
-- example of Memoize function with color generation. Saves speed!
-- saves colors being used, and appends with new colors.
local results = {}
setmetatable(results, {__mode = "v"})
function create_RGB(r,g,b)
-- defining key by the colors used
local key = string.format("%d-%d-%d", r,g,b)
local color = results[key]
@abaez
abaez / easy_open.rs
Last active August 29, 2015 13:57
A quick gist for reader buffer from file.
use std::path::Path;
use std::io::{File, BufferedReader};
/// opens a path to read a file.
fn open(p: &str) -> BufferedReader<File> {
BufferedReader::new(match File::open(&Path::new(p)) {
Ok(f) => f,
Err(e) => panic!("file error: {}", e)
})
}
@abaez
abaez / theme_change.py
Last active August 29, 2015 14:04
Changes theme in termite terminal with base16-builder themes
#!/usr/bin/python
themes = "./themes/"
from os import listdir, chdir
from os.path import isfile, join
from random import randrange
from time import strftime
import sys
@abaez
abaez / codebase.lua
Created August 19, 2014 16:20
Codebase webscript for slack
--- making an example to push to webscript
local icon = "https://pbs.twimg.com/profile_images/378800000410745178/8704302b5009e71d66fbc8f52cefc0bc_400x400.png"
local link = "https://talks.slack.com/services/hooks/incoming-webhook?token="
local token = ""
local fi = json.parse(request.form.payload)
local fo = {
user_email = fi.user.email,
@abaez
abaez / textadept.desktop
Created August 28, 2014 21:23
textadept desktop linux icon with /usr/local install
[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=Textadept
GenericName=Text Editor
Comment=A simple and extensible text editor
Exec=/usr/local/bin/textadept
Icon=/usr/local/share/textadept/core/images/textadept.svg
Terminal=false
@abaez
abaez / keybase.md
Last active September 3, 2015 01:43
identify

Keybase proof

I hereby claim:

  • I am abaez on github.
  • I am baez (https://keybase.io/baez) on keybase.
  • I have a public key whose fingerprint is 18E6 699F 387E 0CC7 6AE6 6B43 0978 8BCC E62B 55B3

To claim this, I am signing this object: