Skip to content

Instantly share code, notes, and snippets.

View PedroAlvesV's full-sized avatar

Pedro Alves Valentim PedroAlvesV

  • Rio de Janeiro, RJ - Brazil
View GitHub Profile
@PedroAlvesV
PedroAlvesV / download.js
Last active March 25, 2020 06:06
js-snippets
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
download(JSON.stringify(jsonData), 'json.txt', 'text/plain');
@PedroAlvesV
PedroAlvesV / Javascript ISO country code to country name conversion
Created March 23, 2020 02:15 — forked from maephisto/Javascript ISO country code to country name conversion
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
@PedroAlvesV
PedroAlvesV / lu.lua
Last active March 11, 2020 07:59
unit tests for LuaMidi
local lu = require('luaunit')
math.randomseed(os.time())
local LuaMidi = require('LuaMidi')
local MIN = {
PITCH = 0x00,
VELOCITY = 0,
REPETITION = 1,
CHANNEL = 1,
local function print_table(t, level)
level = level or 0
local tab = ""
for i=1, level do
tab = tab.."\t"
end
for k,v in pairs(t) do
if type(v)=="table" then
print(tab..k)
print_table(v, level+1)
@PedroAlvesV
PedroAlvesV / deleteFilesInDir.lua
Created January 20, 2020 07:08
snippet to delete files in the current directory
local function contains(t, v)
for index, value in ipairs(t) do
if value == v then
return true
end
end
return false
end
local protected = {
@PedroAlvesV
PedroAlvesV / sha2for51.lua
Created August 31, 2018 18:29
working implementation of SHA512 for Lua 5.1
-- This module contains functions to calculate SHA2 digest.
-- Supported hashes: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256
-- This is a pure-Lua module, compatible with Lua 5.1
-- It works on Lua 5.1/5.2/5.3/5.4/LuaJIT, but it doesn't use benefits of Lua versions 5.2+
-- Input data may must be provided either as a whole string or as a sequence of substrings (chunk-by-chunk).
-- Result (SHA2 digest) is a string of lowercase hex digits.
--
-- Simplest usage example:
-- local your_hash = require("sha2for51").sha512("your string")
@PedroAlvesV
PedroAlvesV / sha1.lua
Created November 8, 2017 23:56
SHA-1 in pure lua
--
-- SHA-1 secure hash computation, and HMAC-SHA1 signature computation,
-- in pure Lua (tested on Lua 5.1)
--
-- Latest version always at: http://regex.info/blog/lua/sha1
--
-- Copyright 2009 Jeffrey Friedl
-- jfriedl@yahoo.com
-- http://regex.info/blog/
--
https://github.com/erlang/otp/wiki/Writing-good-commit-messages
http://issuestats.com/
@PedroAlvesV
PedroAlvesV / supreme_todo.txt
Created March 16, 2017 21:25
supreme abstk todo
unicode implementation
segfault with short selectors (radiolists)
@PedroAlvesV
PedroAlvesV / fixes.txt
Last active April 7, 2017 04:22
abstk TODO list
major:
curses:
textinput scrolling (must track)
minor:
gtk:
radiolists set_value() passing lists with different length than the original (curses is correct)