This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"level": 1, | |
"code": 1, | |
"name": "Aveiro" | |
}, | |
{ | |
"level": 2, | |
"code": 101, | |
"name": "Águeda" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import default_timer as timer | |
from datetime import timedelta | |
start = timer() | |
end = timer() | |
print(timedelta(seconds=end-start)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |