Skip to content

Instantly share code, notes, and snippets.

View alexwebgr's full-sized avatar
😎

Alexandros alexwebgr

😎
View GitHub Profile
@alexwebgr
alexwebgr / creds.rb
Last active August 9, 2021 11:44
How to generate, manage and use env-specific encrypted credentials in rails 5.2
# generate and edit env-specific encrypted credentials
EDITOR=nano bin/rails encrypted:edit config/development.yml.enc --key config/development.key
# override credentials in application.rb
def credentials
encrypted(
"config/#{Rails.env.downcase}.yml.enc",
key_path: "config/#{Rails.env.downcase}.key"
)
end
@alexwebgr
alexwebgr / counter
Last active November 12, 2020 14:36
str = "aabbbaa"
count = Hash.new(0)
str.each_char { |c| count[c] += 1 }
puts count
@alexwebgr
alexwebgr / shell.sh
Last active September 23, 2024 09:40
Install MySQL on ubuntu 20.04 and set the root password
# Completely remove any previous config
sudo apt remove --purge mysql*
sudo apt autoremove
sudo find / -iname mysql
# install the server
sudo apt update
sudo apt install mysql-server
# run the wizard
sudo mysql_secure_installation
PARENS = {
"(" => ")",
"{" => "}",
"[" => "]"
}
OPENING_PARENS = PARENS.keys
CLOSING_PARENS = PARENS.values
def valid_parentheses(string)
stack = []
string.each_char do |ch|
@alexwebgr
alexwebgr / video_loader.js
Created May 30, 2019 09:23
Load youtube videos async
let videos = $(".wpl-youtube");
$.each(videos, function () {
let self = $(this);
let thumbnail = self.find('img');
let play = self.find('.wpl-play');
// Based on the YouTube ID, we can easily find the thumbnail image
thumbnail.attr('src', 'https://i.ytimg.com/vi/' + self.attr('data-id') + '/0.jpg');
play.on({
// requires https://medialize.github.io/URI.js
function updateURL(url, params) {
let new_url = new URI(url);
$.each(params, function (value) {
if (params[value] !== undefined) {
new_url.setSearch(value, params[value]);
} else {
new_url.removeSearch(value);
@alexwebgr
alexwebgr / search_form.js
Created May 30, 2019 09:06
autocomplete search function
var keys = [8,
46,
48,
49,
50,
51,
52,
53,
54,
55,
@alexwebgr
alexwebgr / signature.js
Created May 30, 2019 08:47
Digital signature field
class SignTool {
constructor() {
this.initVars();
this.initEvents();
}
initVars() {
this.canvas = $('#canvas')[0];
this.ctx = this.canvas.getContext("2d");
this.isMouseClicked = false;
@alexwebgr
alexwebgr / growable_text.js
Created May 30, 2019 08:43
resize a textarea as you type
$("textarea.growable")
.on('keyup paste input', function () {
let self = $(this);
let offset = self.innerHeight() - self.height();
if (self.innerHeight() < this.scrollHeight) {
//Grow the field if scroll height is smaller
self.height(this.scrollHeight - offset);
} else {
//Shrink the field and then re-set it to the scroll height in case it needs to shrink
<%= select 'time_range', 'id', Hash.map { |r| [r[:label], r[:name]] }, {selected: params[:time_range], include_blank: true}, {'data-placeholder': 'Select Time Range'} %>