Skip to content

Instantly share code, notes, and snippets.

View aliafshar's full-sized avatar

Ali Afshar aliafshar

View GitHub Profile
@aliafshar
aliafshar / gist:4961373
Created February 15, 2013 16:09
Compare these two in Dart and Python
String get docPath => '${parent.docPath}/${key}';
@property
def docPath(self):
return '%s/%s' % (self.parent.docPath, self.key)
# Goal, to make it easy to define common get/set operations on wrapper classes.
# The implementation has no state of itself, and is constantly proxying the
# "raw" data in the background.
#
# A descriptor is used to automate the process of creating properties. It would
# be extremely easy to generate the File code.
class ApiAttribute(object):
def __init__(self, name, default=None, wrapper=None, read_only=False):
main = print $ sum $ filter isEven $ takeWhile (\x -> x < 4000000) fiblist
where fiblist = 0 : 1 : zipWith (+) fiblist (tail fiblist)
module Main where
digits x = digits' $ reverse $ show x
where
digits' [] = []
digits' (x:xs) = (read [x]:digits' xs)
x2alt [] = []
x2alt (x:y:xs) = (x*2 : y : x2alt xs)
x2alt (x:xs) = (x*2 : x2alt xs)
@aliafshar
aliafshar / gist:8726685
Created January 31, 2014 04:38
What happens when you code too long in Golang then try to use Python
err = check_args({'lat', 'long'})
if err is not None:
return err
@aliafshar
aliafshar / gist:c9320af1e72955fc49db
Created May 8, 2014 02:44
# The following 2 lines should never be seen together. Yet here they are.
# The following 2 lines should never be seen together. Yet here they are.
import httplib2
import requests
# The following 2 lines should never be seen together. Yet here they are.
import httplib2
import requests
class CredentialsAuthorizer(requests.auth.AuthBase):
"""Uses oauth2client credentials to authorize requests requests."""
#: How many times we will retry a request that might need refreshing
retries = 3
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
x >> y = x >>= \_ -> y
fail :: String -> m a
fail msg = error msg
>>> from gcloud import dns
>>> z = dns.create_zone('my-test-zone', PROJECT, EMAIL, PRIVATE_KEY)
>>> z
<Zone:my-test-zone>
>>> z.add_record('aliafshar.org.', 'A', 60, '1.2.3.4')
<Change:...>
from apiclient import errors
# ...
# XXX Auth
# XXX Build a service
##
# Addition of records
#
BODY = {
'additions' : [{