Una posible optimización (para: https://github.com/icodeart/brute-force) sería usar concurrencia. El problema del productor-consumidor [4] serviría en este caso: donde tienes M consumidores (http request workers) y N productores (workers que leen el archivo y vacían contenido a un buffer, de tamaño limitado y a elección, en memoria). De este modo se minimizan los tiempos de espera entre un request I/O y otro, y se maximiza el uso de la red al usar varios workers, explotando el algoritmo scheduling del sistema operativo (véase preemption) [5]. Al existir una tarea I/O que limita la holgura del programa en general, se podría decir, que esto pondera a que el problema sea de tipo I/O (entrada y salida), ya que las comunicaciones por red, son siempre más lentas que el procesamiento en la maquina (CPU). [6] Usar threads virtuales [3] sobre los workers que hacen procesamiento http, sería bueno en este caso. Green-threads [2] son una buena opción también (También ver Python y GIL)[1].
This file contains hidden or 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 convres(x): | |
x = hex(int(x))[2:].zfill(4) | |
return (x[:2], x[2:])[::-1] | |
print 'Commandos 3 resolution converter (Wide x Height)' | |
w = int(raw_input('Wide: ')) | |
h = int(raw_input('Height: ')) | |
print 'first replace: ' + ' '.join(convres(w)) | |
print 'second replace: ' + ' '.join(convres(h)) |
This file contains hidden or 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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import os | |
import sys | |
import signal | |
class MasterDaemon(object): | |
def __init__(self, infn, outfn, errfn): | |
self.infn = infn |
This file contains hidden or 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 wait(): | |
condmut.acquire() | |
sleepQueue.enqueue(P) | |
condmut.release() | |
sleep(P) | |
def signal(): | |
condmut.acquire() | |
P = sleepQueue.dequeue(NoWait) | |
if not P: |
This file contains hidden or 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
import threading | |
mutex1 = threading.Lock() | |
sem_limit = 5 | |
sem_count = sem_limit | |
lista1 = [] | |
def acquire_sem(): | |
mutex1.acquire() | |
if sem_count == 0: |
This file contains hidden or 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
import threading | |
class Semaphore(object): | |
def __init__(self, sem_limit): | |
self.condition1 = threading.Condition(threading.Lock()) | |
self.sem_limit = int(sem_limit) | |
self.sem_count = self.sem_limit | |
def acquire(self): | |
self.condition1.acquire() |
This file contains hidden or 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
require 'open-uri' | |
require 'nokogiri' | |
class AppkedApi | |
def initialize | |
require 'open-uri' | |
require 'nokogiri' | |
end | |
def content(url, entry=true) |
This file contains hidden or 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 User < ActiveRecord::Base | |
has_many :user_clinics | |
has_many :clinics, through: :user_clinics | |
end | |
class UserClinic < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :clinic | |
validate :clinic_validation |
This file contains hidden or 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
#include <stdlib.h> | |
#include <stdio.h> | |
#define EXIT_SUCCESS 0 | |
#define EXIT_FAILURE 1 | |
typedef enum { false=0, true } bool; | |
typedef struct _uf_node { | |
int data; |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'droplet_kit' | |
token = 'put-your-token-id' | |
client = DropletKit::Client.new(access_token: token) | |
if File.exist?('/root/droplet_id') | |
begin | |
droplet_id = File.read('/root/droplet_id') | |
res = client.droplets.delete(id: droplet_id) | |
until res.status == "completed" | |
res = client.actions.find(id: res.id) |