Skip to content

Instantly share code, notes, and snippets.

View dedeco's full-sized avatar
👨‍💻
Can I help you about python? Ask me.

Dedeco dedeco

👨‍💻
Can I help you about python? Ask me.
View GitHub Profile
# More Info: http://davydany.com/post/32287214449/matplotlibs-basemap-plotting-a-list-of-latitude
def show_map(self, a):
# 'a' is of the format [(lats, lons, data), (lats, lons, data)... (lats, lons, data)]
lats = [ x[0] for x in a ]
lons = [ x[1] for x in a ]
data = [ x[2] for x in a ]
lat_min = min(lats)
lat_max = max(lats)
import logging
import threading
import time
"""
3.4 Mutex
A second common use for semaphores is to enforce mutual exclusion.
We have al-ready seen one use for mutual exclusion, controlling concurrent access to sharedvariables.
import logging
import threading
import time
"""
3.5 Multiplex
Puzzle: Generalize the previous solution so that it allows multiple threads to run in the critical section at the same time,
but it enforces an upper limit on the number of concurrent threads.
package com.example.jobs;
import java.util.ArrayList;
import java.util.Arrays;
public class job {
public static void main(String[] args) {
ArrayList<ArrayList<String>> candidates = new ArrayList<ArrayList<String>>();
String[] vaga = { "Java8", "Spring", "NoSQL", "Cloud", "Docker", "UnitTests", "TDD" };
@dedeco
dedeco / test.py
Created November 16, 2019 21:15
Example agnostic test
# -*- coding: utf-8 -*-
import argparse
import collections
import copy
import datetime
import dateutil.parser
import json
from urllib import request, parse
@dedeco
dedeco / rotate_letters.py
Last active December 26, 2019 02:01
Rotate the letters of each city
"""
['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
// YOUR ALGORITHM
[
[ 'Tokyo', 'Kyoto' ],
[ 'London', 'Donlon' ],
[ 'Rome' ],
[ 'Paris' ]
@dedeco
dedeco / count_bits.py
Created January 3, 2020 04:10
Como contar o número do bits 1 para um inteiro (não negativo)
def count_bits(x):
qty_ones = 0
while x:
qty_ones += x & 1
x >>= 1
return qty_ones
if __name__ == "__main__":
print(count_bits(13))
@dedeco
dedeco / parity.py
Created January 14, 2020 04:03
Como computar o bit de paridade?
def parity(x):
result = 0
while x:
result ^= x & 1
x >>= 1
return result
if __name__ == "__main__":
print(parity(42))
@dedeco
dedeco / poll.ex
Created February 23, 2020 05:10
Poll in Elixir
defmodule Poll do
defstruct candidates: []
#Public API
def start_link() do
poll = %Poll{}
spawn_link(Poll, :run, [poll])
end
def exit(pid) when is_pid(pid) do
@dedeco
dedeco / anagram.py
Created August 19, 2020 00:46
Anagram substring quantity
from collections import defaultdict
def count_anagram(str):
subs = defaultdict(int)
for i in range(len(str)):
for j in range(1, len(str) + 1):
if j > i:
subs[''.join(sorted(str[i:j]))] += 1
print(subs)