Skip to content

Instantly share code, notes, and snippets.

View dchaplinsky's full-sized avatar

Dmytro Chaplynskyi dchaplinsky

View GitHub Profile
/*
* This other bot is helping-- somewhat.
*/
var stop = function(self) {
self.thrusters.top(false);
self.thrusters.left(false);
self.thrusters.bottom(false);
self.thrusters.right(false);
}
@dchaplinsky
dchaplinsky / bq9.js
Created January 5, 2014 16:59
guess what
/*
* Open all three doors to exit.
*
* The answer is 5.
*/
var stop = function(self) {
self.thrusters.top(false);
self.thrusters.left(false);
self.thrusters.bottom(false);
self.thrusters.right(false);
/*
* Do it.
*
*/
var current_direction = "top";
var alongside = "";
var flip = {
"top": "bottom",
"bottom": "top",
/*
* Open all three doors to exit.
*
* The answer is ?.
*/
var mode = "centering";
var position = 0;
var sequences = [
[1, 0, 0], // On
@dchaplinsky
dchaplinsky / fuzzywuzzy.diff
Created January 7, 2014 21:35
memoization/optimisations applied to particular fuzzywuzzy method: 4.5x speed up
--- /Users/dchaplinsky/Downloads/fuzz.py 2014-01-07 23:32:54.000000000 +0200
+++ fuzz.py 2014-01-07 23:33:35.000000000 +0200
@@ -94,25 +94,47 @@
# sort those tokens and take ratio of resulting joined strings
# controls for unordered string elements
def _token_sort(s1, s2, partial=True, force_ascii=True):
+ try:
+ sorted1 = _sorted_full_process(s1, force_ascii)
+ except TypeError:
+ raise TypeError("s1 is None")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
class Solution1(object):
def straight(self, rest, pile1, pile2):
self.call_cnt += 1
if not rest:
return ((abs(sum(pile1) - sum(pile2)), pile1, pile2))
if sum(pile1) > self.upper_bound or sum(pile2) > self.upper_bound:
return [1E100]
@dchaplinsky
dchaplinsky / exception
Last active August 29, 2015 14:07 — forked from z4y4ts/exception
Traceback (most recent call last):
File "metrics.py", line 32, in <module>
test()
File "metrics.py", line 27, in test
distance_type='jaccard')
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 201, in create
return self._document(**kwargs).save()
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/mongoengine/document.py", line 241, in save
object_id = collection.save(doc, **write_concern)
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/pymongo/collection.py", line 266, in save
import MySQLdb
import json
import html2text
con = MySQLdb.connect('localhost', 'root', '', 'nashig', use_unicode=True)
with con:
h = html2text.HTML2Text()
h.ignore_links = True
<span class="ner-popup" data-slots="{{ data.slots|tojson }}" data-refs="{{ data.refs|tojson }}" title="{{ data.type }}">