Skip to content

Instantly share code, notes, and snippets.

View CarlosUvaSilva's full-sized avatar

Carlos Silva CarlosUvaSilva

  • Gaspard+Bruno
  • Lisbon
View GitHub Profile
@CarlosUvaSilva
CarlosUvaSilva / docker_nvidia.sh
Last active September 4, 2023 15:52
Allow running multiple GPU "enabled" containers using AWS ECS services
#!/bin/bash
(sudo grep -q ^OPTIONS=\"--default-runtime /etc/sysconfig/docker && echo '/etc/sysconfig/docker needs no changes') || \
(sudo touch /home/ec2-user/test.txt && \
sudo sed -i 's/^OPTIONS="/OPTIONS="--default-runtime nvidia /' /etc/sysconfig/docker && \
echo '/etc/sysconfig/docker updated to have nvidia runtime as default' && \
sudo systemctl restart docker && echo 'Restarted docker')
@CarlosUvaSilva
CarlosUvaSilva / hash_diff.rb
Created January 18, 2022 15:27
2 Hash Diff
def hash_diff(first, second)
first.
dup.
delete_if { |k, v| second[k] == v }.
merge!(second.dup.delete_if { |k, v| first.has_key?(k) })
end
hash_diff({1 => 2}, {1 => 2}) # => {}
hash_diff({1 => 2}, {1 => 3}) # => {1 => 2}
hash_diff({}, {1 => 2}) # => {1 => 2}
@CarlosUvaSilva
CarlosUvaSilva / trigrams.rb
Last active September 4, 2023 15:46
Simple Trigram comparison for 2 strings
class Trigrams
def self.trigramify(str)
trigs = []
str.chars.each_cons(3) { |v| trigs << v.join }
trigs
end
def self.match_ratio(str_1, str_2)
text1_trigs = trigramify(str_1)
text2_trigs = trigramify(str_2)
@CarlosUvaSilva
CarlosUvaSilva / distritos-concelhos-freguesias-Portugal.json
Last active January 8, 2021 13:47 — forked from nancruz/distritos-concelhos-freguesias-Portugal.json
Level 1 = Distrito, Level 2 = Concelho, Level 3 = Freguesia
[
{
"level": 1,
"code": 1,
"name": "Aveiro"
},
{
"level": 2,
"code": 101,
"name": "Águeda"
from timeit import default_timer as timer
from datetime import timedelta
start = timer()
end = timer()
print(timedelta(seconds=end-start))
def gen_dict_extract(key, var):
if hasattr(var,'items'):
for k, v in var.items():
if k == key:
yield v
if isinstance(v, dict):
for result in gen_dict_extract(key, v):
yield result
elif isinstance(v, list):
for d in v:
class Api::V1::UsersController < ApplicationController
before_action :set_item, only: [:show, :update, :reservations]
after_action :verify_authorized, except: :index, unless: -> { @user.nil? }
after_action :verify_policy_scoped, only: [:reservations]
def show
if @user