Skip to content

Instantly share code, notes, and snippets.

View SecurityForUs's full-sized avatar

Eric Hansen SecurityForUs

View GitHub Profile
@SecurityForUs
SecurityForUs / gist:3785180
Created September 25, 2012 23:56
Workaround from using Math functions
def fmt_currency(val):
tmp = val
if not isinstance(tmp, str):
tmp = str(tmp)
if val < 100:
cents = tmp
dollars = "0"
else:
@SecurityForUs
SecurityForUs / gist:3790238
Created September 26, 2012 20:03
example of exception in python for balanced
def addClient(self, email, cardUri):
try:
client = balanced.Marketplace.my_marketplace.create_buyer(email, cardUri)
return True
except balanced.exc.HttpError as e:
if e.category_code == "duplicate-email-address":
buyer = balanced.Account.query.filter(email_address=email)
print buyer
buyer = buyer[0]
try{
$trans = $mp->debits->query()->filter(Balanced\Debit::$f->transaction_number->eq($_POST['id']))->one();
//} catch(Balanced\Exceptions\HTTPError $e){
// die(json_encode(array("error" => "No transaction found.")));
} catch(Balanced\Exceptions\MultipleResultsFound $e){
print_r($e);die;
//die(json_encode(array("error" => "No transaction found.")));
}
>>> num = "100"
>>> print sum([int(x)*(2**int(z)) for z,x in enumerate(num[::-1])])
4
def search_cc(self, cc):
if not isinstance(cc, str):
cc = str(cc)
if len(cc) < 4:
print "Invalid length for CC"
return False
try:
cards = list(balanced.Marketplace.query.one().cards)
@SecurityForUs
SecurityForUs / gist:3805659
Created September 30, 2012 02:17
get all cards for one account
def testing(self, addr):
cards = None
try:
buyer = balanced.Account.query.filter(email_address=addr)[0]
cards = list(balanced.Card.query.filter(card_uri=buyer.cards_uri))
except:
pass
return cards
conf['system']['log_level'] = "debug,info"
try:
conf_level = conf['system']['log_level'].split(",")
LEVELS = { "debug" : logging.DEBUG, "info" : logging.INFO, "warning" : logging.WARNING, "error" : logging.ERROR, "critical" : logging.CRITICAL}
for level in conf_level:
self.log.setLevel(LEVELS[level])
except:
class ClassBase:
def __init__(self, log_name, client = True):
try:
self.conf
except:
self.conf = Config()
try:
self.log
except:
def head(self, options):
try:
if options['method'] is not "":
url = "%s/%s" % (options['url'], options['method'])
else:
url = "%s" % (options['url'])
except:
raise APIException("No API method call provided.")
try:
class APIBase(ClassBase):
# Both SL and SVB require authentication tokens. So we set a field here for them
tokens = {'sl' : "", 'svb' : ""}
# Enable support for proxies
proxy = {"https" : ""}
def __init__(self, class_name = "api.base"):
ClassBase.__init__(self, class_name)