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
sudo apt-get update | |
sudo apt-get install git-core | |
sudo apt-get install python-pip python-dev build-essential | |
sudo apt-get install libxml2-dev | |
sudo apt-get install libxslt1-dev | |
sudo pip install --upgrade pip | |
sudo pip install virtualenvwrapper | |
sudo apt-get install libmysqlclient-dev | |
echo "export WORKON_HOME=$HOME/.virtualenvs" >> .bashrc | |
echo "export PROJECT_HOME={path to project}" >> .bashrc |
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
/** | |
* @return bool | |
*/ | |
public function close() | |
{ | |
$result = TRUE; | |
if ($this->connected && !$this->persistent) { | |
try { | |
$result = $this->standalone ? fclose($this->redis) : $this->redis->close(); | |
$this->connected = FALSE; |
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 _amount_residual(self, cr, uid, ids, name, args, context=None): | |
"""Function of the field residua. It computes the residual amount (balance) for each invoice""" | |
if context is None: | |
context = {} | |
ctx = context.copy() | |
result = {} | |
currency_obj = self.pool.get('res.currency') | |
for invoice in self.browse(cr, uid, ids, context=context): | |
nb_inv_in_partial_rec = max_invoice_id = 0 | |
result[invoice.id] = 0.0 |
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 poster.encode import multipart_encode | |
from poster.streaminghttp import register_openers | |
import urllib2 | |
register_openers() | |
datagen, headers = multipart_encode({"fileUpload": open("filaname.jpg")}) | |
request = urllib2.Request("https://www.filepicker.io/api/store/S3?key={yourKey}", \ | |
datagen, headers) | |
response = urllib2.urlopen(request) |
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
func main() { | |
. | |
. | |
<-done | |
// continue program execution | |
} |
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
// allocate allocates jobs based on an array of resources to be processed by the worker pool | |
func (m *Manager) allocate(jobs []interface{}) { | |
defer close(m.jobs) | |
for i, v := range jobs { | |
job := Job{id: i, resource: v} | |
m.jobs <- job | |
} | |
} |
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
// workerPool creates or spawns new "work" goRoutines to process the "Jobs" channel | |
func (m *Manager) workerPool(processor ProcessorFunc) { | |
defer close(m.results) | |
var wg sync.WaitGroup | |
for i := 0; i < m.numRoutines; i++ { | |
wg.Add(1) | |
go m.work(&wg, processor) | |
} | |
wg.Wait() | |
} |
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
// work performs the actual work by calling the processor and passing in the Job as reference obtained | |
// from iterating over the "Jobs" channel | |
func (m *Manager) work(wg *sync.WaitGroup, processor ProcessorFunc) { | |
defer wg.Done() | |
for job := range m.jobs { | |
output := Result{job, processor(job.resource)} | |
m.results <- output | |
} | |
} |
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
// Collect post processes the channel "Results" and calls the ResultProcessorFunc passed in as reference | |
// for further processing. | |
func (m *Manager) Collect(proc ResultProcessorFunc) { | |
for result := range m.results { | |
outcome := proc(result) | |
fmt.Printf("Job with id: [%d] completed, outcome: %s", result.job.id, outcome) | |
} | |
m.done <- true | |
} |
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
func main() { | |
pool := workerpool.NewPool(3) // 3 goRoutines(workers) | |
pool.Start(resources, ResourceProcessor, ResultProcessor) | |
} |
OlderNewer