Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Can I help you about python? Ask me.

Dedeco dedeco

👨‍💻
Can I help you about python? Ask me.
View GitHub Profile
View show_map.py
# 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)
View 3.4-mutex.py
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.
View 3.5-multiplex.py
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.
View job.java
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 Nov 16, 2019
Example agnostic test
View test.py
# -*- 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 Dec 26, 2019
Rotate the letters of each city
View rotate_letters.py
"""
['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
// YOUR ALGORITHM
[
[ 'Tokyo', 'Kyoto' ],
[ 'London', 'Donlon' ],
[ 'Rome' ],
[ 'Paris' ]
@dedeco
dedeco / count_bits.py
Created Jan 3, 2020
Como contar o número do bits 1 para um inteiro (não negativo)
View count_bits.py
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 Jan 14, 2020
Como computar o bit de paridade?
View parity.py
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 Feb 23, 2020
Poll in Elixir
View poll.ex
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 Aug 19, 2020
Anagram substring quantity
View anagram.py
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)