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
# 3 = 2^2 | |
# x = 2 | |
def qsort(arr): | |
print(arr) | |
if len(arr) == 0: | |
return arr | |
pivot = arr[0] | |
sup_arr = [] |
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 collections import deque | |
grafo = {} | |
grafo["voce"] = ["alice", "bob", "claire"] | |
grafo["bob"] = ["anuj", "peggy"] | |
grafo["alice"] = ["peggy"] | |
grafo["claire"] = ["thom", "jonny"] | |
grafo["anuj"] = [] | |
grafo["peggy"] = [] | |
grafo["thom"] = [] |
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
(define (fact x) | |
(if (= x 0) 1 | |
(* x (fact (- x 1))))) | |
(define (fact x) | |
(define (fact-tail x accum) | |
(if (= x 0) accum | |
(fact-tail (- x 1) (* x accum)))) | |
(fact-tail x 1)) |
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
class ReadWriteSerializerMethodField(serializers.Field): | |
def __init__(self, method_name=None, **kwargs): | |
self.method_name = method_name | |
kwargs['source'] = '*' | |
#kwargs['read_only'] = True | |
super(ReadWriteSerializerMethodField, self).__init__(**kwargs) | |
def bind(self, field_name, parent): | |
self.field_name = field_name | |
# In order to enforce a consistent style, we error if a redundant |
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
""" | |
user=> (transduce (map inc) + 0 [1 2 3]) | |
9 | |
user=> (transduce (map inc) - 10 [1 2 3]) | |
-1 | |
""" | |
def transduce(transducer, reducer, iterable, memo): | |
return reduce(transducer(reducer), iterable, memo) |
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
(defn transducer [rf] | |
(fn | |
([] (rf)) | |
([result] (rf result)) | |
([result input] (rf result input)))) | |
(defn transducer [rf] # rf eh + | |
(fn | |
([result] (rf result 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
(define (add-streams s1 s2) | |
(stream-map + s1 s2)) | |
(define (scale-stream stream factor) | |
(stream-map (lambda (x) (* x factor)) stream)) | |
(define (integral delayed-integrand initial-value dt) | |
(define int | |
(cons-stream initial-value | |
(let ((integrand (force delayed-integrand))) |
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 derive(obj): | |
from django.contrib.admin.utils import NestedObjects | |
from django.db import DEFAULT_DB_ALIAS | |
from django.db.models.fields.related import ForeignKey | |
""" | |
Derive a new model instance from previous one, | |
and point all related fields to the new instance | |
""" | |
obj2 = copy.copy(obj) | |
obj2.pk = None |
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 get_image_file(name='test.png', ext='png', size=(50, 50), color=(256, 0, 0)): | |
from StringIO import StringIO | |
from PIL import Image | |
from django.core.files import File | |
file_obj = StringIO() | |
file_obj.write('') | |
image = Image.new("RGBA", size=size, color=color) | |
image.save(file_obj, ext) | |
file_obj.seek(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
function debounce(fn, delay) { | |
var timer = null; | |
return function () { | |
var context = this, args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
fn.apply(context, args); | |
}, delay); | |
}; | |
} |
NewerOlder