Skip to content

Instantly share code, notes, and snippets.

>>> import re
>>> array = ["1test", "2test", "notanumber", "3bananas"]
>>> re.match("^[1-9]", "1testing")
<_sre.SRE_Match object at 0x1004743d8>
#a synonym for [1-9] is \d
>>> re.match("^\d", "1testing")
<_sre.SRE_Match object at 0x100474440>
from string import digits
x = ["1a", "2b", "2b", "3c", "5e"]
#the clearest, most basic way I can think of
numbers = {}
for i in x:
first = i[0]
if first in digits:
if first in numbers:
import re
testtext = """1 22 333 444 555 666 777 888 999
999 999 999 testing something else 1bananas"""
# Benford's law applies only to numbers, not to words starting with numbers like '1bananas',
# so let's use a regex to find all the numbers in the text:
numbers = re.findall(r"\b\d+\b", testtext)
# here's how to understand that regular expression:
# 1. You can access strings just like they were arrays, with []:
s = "testing"
assert s[0] == "t"
#which means that you don't need to split each number like you do in lines 36 and 37
# 2. If you ever find yourself writing out numbers in sequence, you're probably doing something
# better accomplished with a for loop. Thus, this:
for number in datalist:
if number[0] == '1':
#problem 1
one = "en3pG3+nz+A2acXKrsyDouhViP9EDQS4JQK6uJqM3rBjKEBKC3yc=AA1=LUQqRPHvQ4dopgkbb/axClP3smzVcaTkRsCqHSG5aKFQ2TbOae0t5r4nWrCVesGK1Z3yEq+dClrDwXXOiAMyW09WdCS+CaKcfu=6kv9dUFBcS4KsUIgwMiXimoBpJZSWlBzILVf4zVA=7GjRP8RXn6uKjbjAPkpFEs/mYJpeOpEnhQfPhjoscgjfL5/SQsU6+jaAf5pg9MQzZdQAEJt7Jm1541fEmnumpjmJMd/MTJ5vzBttBBA7b5rbjDX0nHdTWn8C5suYKfNyYzc6x8S6FIepoEBsMS2mKhx5BRH5jSBrYRem4iQgYARzGnCFot3jPhp3cHj7qjXBWfZZASz8YJqi2d+r393AmdGm1L9NfU2f=FJprbLwJpuE7uT7xAlQA3Ry8aHRNgNkffP29Iqb2DSoQ0PK+9LX0t37HIAhI5zvoP6b4J7yQZEQDgeNlnPQMvSjw9pLWAxQ1VUY+NMU5BLZ2Bxuma1cIsHxcx4PwHcg0u1HYPJAWM2WK=xhJP5aQSc6oNMQK4s2=6guQRVFll6rvWkXTebrdsws7m/Kpa29spUFl8XzFx0ondEMCF3byAyWj875wAI3Hn8ZY92ddTAKj0s+a4X7qSti2lA0GzePHjBjMCD5g9kZYLtB94kkbVZ6eCle/xtto4LHH8GElc5YoUi=mk3nmQ5iOL1zMWfDyRUMLq+HCXbQL9NTejNa/yTdL3sayJOlMW1T7/Jmaz1FMbfBRFzruHeMT41=Zu3nYZJ3nIP22qKrFzNkt/24RuQ+7IMVCI2ngh2Yr8qLiL7QjSThRJPxA1wIJXwR2wqGiMhOqpun4DyQ5b/fTw1eTavpbFg6+tvqS4GKOt6p=bPoTV0GHIBBlXgHF/GUss90N0mXMKKiGwHhn/kyz=FxN0j=mfQUuUQa7lrZLjr10sqflWTwskIUkp1Cd8GYU4PaeWxiMBYFn
<html><head><title>test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script>
//the images array. Each group of 8 images should be a row in the images table
var images = [
["http://i.imgur.com/YpJyG.jpg", "http://i.imgur.com/1hUh9.jpg"],
["http://i.imgur.com/4cWJ2.jpg", "http://i.imgur.com/H60Es.jpg"]
]
//default one second timeout, set to anything you want
#!/usr/bin/python
# recreate the Sobel edge video demo from http://morepypy.blogspot.com/2011/07/realtime-image-processing-in-python.html
# in regular python, using openCV's python bindings.
#
# here's a screenshot: https://skitch.com/llimllib/fkry5/test.py-vim1
#
# this is not meant to say anything about performance! I just think it's neat to run, and
# opencv makes it nice and simple to write. (It does run perfectly in real time, though. I
# didn't bother to count the FPS.)
> schema = {
> "$schema" => "http://json-schema.org/draft-03/schema#",
> "type" => "object",
> "properties" => { "a" => {"format" => "uri"}}
> }
> JSON::Validator.validate(schema, {"a" => 12})
=> true
#1. Ensure that rvm is gonezo
if [ -d "$HOME/.rvm" ]
then
echo "removing .rvm"
rm -rf $HOME/.rvm
else
echo "no rvm dir found"
fi
echo "first, let's set the CC to gcc-4.2"
==> Downloading http://download.osgeo.org/gdal/gdal-1.8.1.tar.gz
File already downloaded in /Users/bill/Library/Caches/Homebrew
/usr/bin/tar xf /Users/bill/Library/Caches/Homebrew/gdal-1.8.1.tar.gz
==> ./configure --prefix=/usr/local/Cellar/gdal/1.8.1 --disable-debug --with-local=/usr/local/Cellar/gdal/1.8.1 --with-threads --with-libtool --with-libtiff=internal --with-geotiff=internal --with-pcraster=internal --with-pcidsk=internal --with-bsb --with-grib --with-pam --with-libz=/usr --with-png=/usr/X11 --with-expat=/usr --with-sqlite3=/usr --with-jpeg=/usr/local --with-jpeg12 --with-gif=/usr/local --with-curl=/usr/bin/curl-config --without-grass --without-libgrass --with-dods-root=no --without-cfitsio --without-netcdf --without-ogdi --without-hdf4 --without-hdf5 --without-openjpeg --without-jasper --without-xerces --without-epsilon --without-spatialite --without-libkml --without-poppler --without-msg --without-mrsid --without-jp2mrsid --without-kakadu --without-fme --without-ecw --without-dwgdirect --without-p