Skip to content

Instantly share code, notes, and snippets.

View dlitvakb's full-sized avatar

David Litvak Bruno dlitvakb

View GitHub Profile

New NetDNA REST API Clients

On a previous post we've talked abut our new REST API and the benefits it provides to our power users. If that was not enough for your satisfaction, we are releasing REST Clients for Python and Ruby to help you use our service without having worry about anything.

Forget about OAuth problems

from unittest import TestCase, main
from netdnarws import NetDNA
class SomeDescritptiveTestName(TestCase):
def setUp(self):
self.api = NetDNA("alias",
"xxx",
"xxx",
"lrws.netdna.com",
import json
import requests
from oauth_hook import OAuthHook
class NetDNAOAuthHook(OAuthHook):
def __init__(self, consumer_key, consumer_secret, token=None,
token_secret=None, header_auth=True, **kwargs):
#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
@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 []
//Este funciona
{
action_params: { },
display_name: "Flag as inappropriate",
action_type: "external_link",
preconditions: {
hard_dependencies: false,
dependencies: [ ],
precondition_data: {
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
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);
},
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);
try:
# ...
try:
hago_algo_que_puede_llegar_a_romper()
except Exception, e:
raise MiExceptionMasBonita(e)
# ...