Skip to content

Instantly share code, notes, and snippets.

View dlitvakb's full-sized avatar

David Litvak Bruno dlitvakb

View GitHub Profile
class Entity(object):
errors = {}
validators = {}
def __init__(self, **kwargs):
for name, value in kwargs.iteritems():
try:
if self._is_extra_property(name, value):
self._extra_properties(name, value)
@dlitvakb
dlitvakb / gist:1585704
Created January 9, 2012 23:41
require.py
class Require(object):
@staticmethod
def assert_equals(expected, expectee, comment="")
try:
assert expected == expectee
except AssertionError:
comment = "%s, " if comment
raise AssertionError(comment + "expected: %r, but was: %r" % (expected, expectee))
@dlitvakb
dlitvakb / gist:1590081
Created January 10, 2012 17:17
map vs list comprehension
import timeit
def strip(a_string):
return a_string.strip()
results_map = []
results_list_comprehension = []
comp_list = [' 123', ' 123', '123', '123 ','123 ']
def strip_map():
try:
# ...
try:
hago_algo_que_puede_llegar_a_romper()
except Exception, e:
raise MiExceptionMasBonita(e)
# ...
is_mismatch: function (alert) {
return alert.alert_tyoe === "listing_mismatch";
},
is_info_missing: function (alert) {
return alert.alert_type === "listing_info_missing";
},
has_mismatch: function () {
var that = this;
return _.any(this.alerts, function (alert) {
return that.is_mismatch(alert);
render_mismatch: function (self, mismatch_type, default_value) {
return (self['has_' + mismatch_type + '_mismatch']()) ?
self['get_' + mismatch_type + '_diff']() :
default_value;
},
render_name_mismatch: function () {
return this.render_mismatch(this, 'name', this.name);
},
def _verify_new_instances_for_existing_businesses(subscription_group, new_groups):
for subscription in subscription_group['subscriptions']:
for instance_group in new_groups:
if subscription['monitored']['business_id'] == instance_group['business_id']:
for instance in instance_group['instances']:
update = False
old_instances = [ monitored_item['instance'] for monitored_item in monitored['monitored_list'] ]
if not instance in old_instances:
update = True
//Este funciona
{
action_params: { },
display_name: "Flag as inappropriate",
action_type: "external_link",
preconditions: {
hard_dependencies: false,
dependencies: [ ],
precondition_data: {
@dlitvakb
dlitvakb / deklarativna-clj.clj
Created June 26, 2012 19:36
A little XML/xHTML templating engine for learning clojure
;; A little XML/xHTML templating engine as an excercise for learning clojure
(defn attr [a-map]
^{:doc "renders an attribute"
:test (fn []
(assert (= "class='hola'" (attr {:name "class", :value "hola"}))))}
(str (:name a-map) "='" (:value a-map) "'"))
(defn as-attr-list [ats]
^{:doc "renders a list of attributes"
:test (fn []
#NetDNA API Sample Code - Python
#Version 1.0a
# Thanks to @sajal from TurboBytes.com for getting this script started
# Contributed: @jdorfman & the @netdna family
import oauth.oauth as oauth
import httplib2, json
import pprint