... or Why Pipelining Is Not That Easy
Golang Concurrency Patterns for brave and smart.
By @kachayev
var Comment = {] | |
Comment.create = function (attrs) { | |
return m.request({ method: 'POST', url: '/comments', data: attrs }) | |
} | |
// A view-model is basically a temporary, disposable copy of a model. | |
// It allows the user can either commit or cancel the changes they make. | |
Comment.vm = function (attrs) { | |
attrs = attrs || {} |
# -*- encoding:utf-8 -*- | |
from __future__ import print_function | |
class BSTNode(object): | |
def __init__(self, key, value=None, left=None, right=None): | |
self.key = key | |
self.value = value | |
self.left = left |
#traduzido e adaptado de http://blog.trinket.io/writing-poetry-in-python/ | |
from random import choice, randint | |
adjetivos = '''compreensivo temperamental confiável confiável honesto desonesto | |
interessante chato carinhoso simpático amigável generoso ciumento invejoso | |
inseguro ambicioso ansioso bondoso sensato sensível teimoso preguiçoso | |
trabalhador calmo paciente inteligente esperto espirituoso astuto neurótico | |
ousado apático cínico sarcástico irônico cético alegre conservador pessimista | |
otimista tolerante corajoso educado mal-educado determinado sociável | |
solidário arrogante maldoso desajeitado burro independente confiável dependente |
... or Why Pipelining Is Not That Easy
Golang Concurrency Patterns for brave and smart.
By @kachayev
#!/usr/bin/env python | |
def curry(func): | |
""" | |
Decorator to curry a function, typical usage: | |
>>> @curry | |
... def foo(a, b, c): | |
... return a + b + c |
Porting an application across platforms is never particularly easy, nor very interesting. In fact, it's usually a terrible idea: in general, if it ain't broke, don't fix it. But sometimes you have to do it. Maybe a new platform has a feature you believe you can't live without, or the project scope is expanding in directions that make you feel like your original platform choice might not have been the best, or maybe it's just necessary to port for political reasons. Whatever.
#!/bin/bash | |
# Compile Main for Java bytecode | |
gcj -C Main.java | |
# Compile Main for native | |
gcj -findirect-dispatch -fno-indirect-classes -fpic -c Main.class -o java.o | |
# Generate header file | |
gcjh -cp . Main |
# video.rb | |
class Video < ActiveRecord::Base | |
has_many :categorizations | |
has_many :categories, through: :categorizations | |
end | |
# category.rb | |
class Category < ActiveRecord::Base | |
has_many :categorizations | |
has_many :videos, through: :categorizations |
foo = (f1, f2) -> | |
f1() | |
f2() | |
# Doesn't work -- syntax error | |
# foo(-> console.log("hi from f1"), -> console.log("hi from f2")) | |
# Simplest way I've found to do it -- newlines added for clarity | |
foo( | |
(-> console.log("hi from f1")), |
import os | |
import pymongo | |
MONGO_URL = os.environ.get('MONGOHQ_URL') | |
if MONGO_URL: | |
# Get a connection | |
conn = pymongo.Connection(MONGO_URL) | |
# Get the database |