Skip to content

Instantly share code, notes, and snippets.

View kriansa's full-sized avatar

Daniel Pereira kriansa

View GitHub Profile
@kriansa
kriansa / myezbkp.sh
Created October 31, 2011 15:33
Easy MySQL incremental backups
#!/bin/sh
# ========================================================= #
# MyEzBkp
# Easy and simple backup of your entire MySQL Server.
#
# Ver: 1.0
# By: Kriansa
#
# This script requires root privileges to run!
# Tested only in RHEL based distros (Fedora & CentOS)
@kriansa
kriansa / gist:5885902
Created June 28, 2013 16:12
Simple Javascript template parser
/**
* Replaces any ${variables} in the template string by the data object
*/
var parseTemplate = function(template, data) {
return template.replace(/\$\{([\w\d]+)\}/g, function(token, variable){
return data[variable];
});
}
@kriansa
kriansa / string-normalize.js
Created July 25, 2013 21:00
Function to translate accented characters to ASCII equivalents. Stripped out from SugarJS. (https://github.com/andrewplummer/Sugar/)
/**
* Returns the string with accented and non-standard Latin-based characters converted into ASCII approximate equivalents.
*
* @returns {String}
*/
String.prototype.normalize = function() {
var NormalizeSource = {
'A': /[AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ]/g,
'B': /[BⒷBḂḄḆɃƂƁ]/g,
'C': /[CⒸCĆĈĊČÇḈƇȻꜾ]/g,
@kriansa
kriansa / CitiesController.rb
Created August 14, 2013 19:00
Automatizando a seleção de Municípios/UF
class CitiesController < ApplicationController
def all_by_state_id
uf = params[:id]
cities = City.joins(:state).where('states.id' => uf).select('cities.id, cities.name')
render :json => { data: { cities: cities } }
end
end
@kriansa
kriansa / exec_with_timeout.rb
Last active August 29, 2015 14:08
Tiny helper to execute a external command with a timeout.
# Open stdout and stderr streams and start external executable with timeout.
# The timeout is given in seconds.
#
# Block form:
#
# exec_with_timeout(timeout, [env,] cmd... [, opts]) {|stdout, stderr|
# stdout.read
# ...
# }
#
@kriansa
kriansa / openssl_tls_1.2.patch
Last active April 14, 2020 12:26
Source patch to add support to TLS 1.1 and 1.2 to Ruby 1.9.3 - https://garajau.com.br/2015/07/tls-1-1-and-1-2-support-for-ruby-1-9-3
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -107,6 +107,18 @@
OSSL_SSL_METHOD_ENTRY(TLSv1),
OSSL_SSL_METHOD_ENTRY(TLSv1_server),
OSSL_SSL_METHOD_ENTRY(TLSv1_client),
+#if defined(HAVE_TLSV1_2_METHOD) && defined(HAVE_TLSV1_2_SERVER_METHOD) && \
+ defined(HAVE_TLSV1_2_CLIENT_METHOD)
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2),
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2_server),

Keybase proof

I hereby claim:

  • I am kriansa on github.
  • I am kriansa (https://keybase.io/kriansa) on keybase.
  • I have a public key whose fingerprint is BC27 7BE0 9E8A 6F10 59C3 911B 3E78 8475 6312 F945

To claim this, I am signing this object:

@kriansa
kriansa / evdev
Created April 15, 2019 03:00
XKB keyboard multimedia function keys
# Append this content to the file /usr/share/X11/xkb/rules/evdev
#
# Custom options patch by Kriansa
! option = symbols
custom:multimedia_fn_keys = +media(multimedia_fn_keys)
custom:scroll_lock_key_usable = +media(scroll_lock_key_usable)
@kriansa
kriansa / dedup.sh
Created August 9, 2020 14:39
Make hardlinks out of a list of duplicate files generated by rdfind
#!/usr/bin/env bash
help() {
echo "Makes hardlinks out of a list of duplicates files generated by rdfind."
echo
echo "usage: $0 <duplicates_file>"
}
main() {
local duplicates_file=$1
@kriansa
kriansa / vultr-ssh-updater.sh
Created February 8, 2022 03:41
Update your Vultr firewall rules for your ingress SSH
#!/usr/bin/env bash
#
# Automatically updates the IP addresses for the ingress rules for SSH access on Vultr
#
# Requires: jq, curl, dig
main() {
export VULTR_API_KEY="YOUR-VULTR-API-KEY"
# Get existing rules at the Vultr firewall