Skip to content

Instantly share code, notes, and snippets.

$words = explode(" ",$trendResults['model_words']);
$weights = explode(" ",$trendResults['model_weight']);
$word_weights = array();
for ( $i = 0; $i <= sizeof($words); $i += 1) {
$word_weights[$i] = $weights[$i];
}
arsort($word_weights);
$wordLimit = 4;
$idxs = array();
foreach($word_weights as $index => $weight){
def colorcycle(steps):
colors = [colorsys.hsv_to_rgb(i / 1.1 / steps, 1, 1) for i in range(steps)]
return ['#%02x%02x%02x' % (r * 255, g * 255, b * 255) for r,g,b in colors]
>>> def foo():
... raise StopIteration
...
>>> list(foo())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in foo
StopIteration
>>> def foo():
... raise StopIteration
ALTER TABLE `fact`.`news_events_clue` MODIFY COLUMN `article_id` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
MODIFY COLUMN `relation` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
MODIFY COLUMN `primary_parameters` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
MODIFY COLUMN `optional_parameters` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
MODIFY COLUMN `sentence` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
MODIFY COLUMN `version` VARCHAR(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
@erikfrey
erikfrey / gist:652437
Created October 28, 2010 22:09
crazy templates
#ifndef BOOST_SERIALIZATION_UNORDEREDMAP_HPP
#define BOOST_SERIALIZATION_UNORDEREDMAP_HPP
#include <boost/unordered_map.hpp>
#include <boost/config.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
class Foo:
def __init__(self):
self.bar = lambda: Foo.bar(self)
@staticmethod
def bar(self=None):
print 'called with self: %s' % self
class Foo:
def __init__(self):
self.bar = lambda: Foo.bar(self)
@staticmethod
def bar(self=None):
print 'called with self: %s' % self
@erikfrey
erikfrey / gist:865355
Created March 11, 2011 02:20
Threadpool crashes gevent
from threadpool import ThreadPool
import random
import gevent
import gevent.pool
iterations = 1000000
max_stack_depth = 50
def source(tp):
for i in xrange(0, iterations):
import gevent
import gevent.pool
import multiprocessing
def child_runner():
p = multiprocessing.Process(target=child)
p.start()
print gevent.getcurrent()
def child():
@erikfrey
erikfrey / gist:878950
Created March 21, 2011 03:01
child_runner is spawned 2^SPAWN_COUNT times
import gevent
import gevent.pool
import multiprocessing
SPAWN_COUNT = 5
def child_runner():
p = multiprocessing.Process(target=child)
p.start()
print gevent.getcurrent()