This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VPN_NAME="" | |
i=0 | |
VPN_COUNT=5 | |
random=$RANDOM | |
for name in "Germany" "USA" "Canada" "Netherlands" "Sweden" | |
do | |
if (( random % VPN_COUNT == ++i )); then | |
VPN_NAME=$name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro render_field(field) %} | |
<dt>{{ field.label }}</dt> | |
<dd>{{ field(**kwargs)|safe }} | |
{% if field.errors %} | |
<ul class="alert alert-error"> | |
{% for error in field.errors %} | |
<li>{{ error }}</li> | |
{% endfor %} | |
</ul> | |
{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_email(form, to, name): | |
recipient = "%s <%s>" % (name, to) | |
subject = form.subject.data | |
sender = "%s <%s>" % (form.name.data, users.get_current_user().email()) | |
body = form.body.data | |
try: | |
mail.send_mail(sender=sender, to=recipient, subject=subject, body=body) | |
return True | |
except: | |
logging.error(traceback.extract_stack()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_phone_number(form, field): | |
digits = filter(lambda x: x.isdigit(),field.data) | |
if len(digits) != 10 and len(digits) != 7: | |
raise validators.ValidationError(u'Invalid phone number') | |
def is_valid_header(form, field): | |
if '\n' in field.data or '\r' in field.data: | |
raise validators.ValidationError(u'Email headers cannot contain newlines') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@evalcontextfilter | |
def to_phone_number(eval_ctx, value): | |
#Start by ensuring string has 10 digits | |
digits = filter(lambda x: x.isdigit(),value) | |
if len(digits) == 10: | |
phone_number = '(%s)%s-%s'%(digits[0:3], digits[3:6], digits[6:]) | |
else: | |
phone_number = '%s-%s'%(digits[0:3], digits[3:]) | |
if eval_ctx.autoescape: | |
return Markup(phone_number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@evalcontextfilter | |
def boolval2yesno(eval_ctx, value, true="Yes", false="No"): | |
if value: | |
result = true | |
else: | |
result = false | |
if eval_ctx.autoescape: | |
result = Markup(result) | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Usage | |
#Initiate a new instance of an OurVleBrowser | |
browser = OurVleBrowser() | |
''' | |
Returns dict in the form: | |
{ | |
'name' : '[NAME]', | |
'courses' : [ { 'id' : '[COURSE_ID]', 'title' : '[COURSE_TITLE]', 'url' : '[COURSE_URL]' } ] | |
} | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
sas.py | |
Logs in to a student's SAS account and gets their schedule, then parses the relevant information using regex, because | |
SAS's HTML is too ugly to use a parser. | |
Todo: | |
(!) Refactor times returned by the parser to datetime objects to allow for easy time-related operations. | |
Or not, because it's just a prototype, and that's a lot of effort for a proof-of-concept | |
''' | |
import urllib2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Discrete Math Homework | |
import math | |
def fib_check(l): | |
def is_fibonacci(n): | |
phi = 0.5 + 0.5 * math.sqrt(5.0) | |
a = phi * n | |
return n == 0 or abs(round(a) - a) < 1.0 / n | |
#Check if each number in list is fibonacci | |
if sorted(l) == l: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: url('http://www.cs.washington.edu/education/courses/cse190m/12su/homework/2/background.png'); | |
font-family: 'Tahoma', 'Verdana', 'sans-serif'; | |
font-size: 8pt; | |
margin: 0; | |
padding: 0; | |
} | |
dt { | |
font-weight: bold; |
OlderNewer