Skip to content

Instantly share code, notes, and snippets.

import requests
url = 'https://ets.aeso.ca/'
cert_key = ('cert.pem', 'key.pem')
headers = {'User-Agent': 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko'}
r = requests.get(url, cert=cert_key, verify=False)
print r.text
@rpq
rpq / ccrdab
Created January 14, 2016 18:49
def _client_specific_post_standard_scrub_updates_ccrd(self):
kwargs = {'client': self.client, 'infile': self.client_infile.infile}
if self.client_infile.commodity in ('E', 'G'):
kwargs['commodity'] = self.client_infile.commodity
kwargs['rate_plan_type__rate_plan_type_abbrev'] = 'var'
kwargs['svc_start_date__isnull'] = False
kwargs['svc_start_date__lt'] = F('file_date')
# add transaction block
service_end_date = self.file_date + datetime.timedelta(months=6)
CustomerCountsRaw.objects.filter(**kwargs).update(
@rpq
rpq / get_indexes_from_mbox
Created April 8, 2015 17:19
Gets all byte indexes for each individual mbox message in a mbox file format (this implementation works on gmail mbox)
import re
class BufferFileReader(object):
def __init__(self, file_path, size):
self.last_offset = 0
self.file_path = file_path
self.size = size
self.fp = open(self.file_path, 'r')
@rpq
rpq / gist:5655d2cfa7ab6b6c431b
Created December 2, 2014 22:08
test the django management command snippet
106 fixture = ("/Users/quezadar/projects/b2b-frontend/B2B/src/b2b/tests/"
107 "fixtures/initial_data.json")
108 cmd = 'manage.py loaddata \'%s\'' % (fixture,)
109 s = StringIO.StringIO()
110 sys_stdout = sys.stdout
111 sys_stderr = sys.stderr
112 sys.stdout = s
113 sys.stderr = s
114 execute_from_command_line(cmd.split(' '))
115 sys.stdout = sys_stdout
@rpq
rpq / django_test_admin_login
Created September 18, 2014 13:35
django admin testing login
31 +class AdminLoginMixin(object):
40 32
41 33 def _create_user(self):
42 34 self.TEST_USERNAME = 'testusername'
43 35 self.TEST_PASSWORD = 'testpassword'
44 36
45 37 u, created = auth_models.User.objects.get_or_create(
46 38 username=self.TEST_USERNAME)
47 39 if created:
48 40 u.set_password(self.TEST_PASSWORD)
@rpq
rpq / compact_and_flatten
Created September 12, 2014 18:31
compact and flatten python
20 def compact_array(list_, i=0):
21 if i == len(list_):
22 return []
23 if not list_[i]:
24 return [] + compact_array(list_, i + 1)
25 return [list_[i]] + compact_array(list_, i + 1)
26
27 def flatten_array(flatten):
28 def has_array(list_):
29 return any((isinstance(li, list) for li in list_))
@rpq
rpq / gist:7282916
Created November 2, 2013 20:05
compile on ruby/trunk 11/2/2013 4pm EST
converter from UTF-8 to Big5-UAO
make[1]: *** [enc/trans/big5.c] Killed
make[1]: Leaving directory `/home/rpq/.local/src/ruby'
make: *** [srcs-enc] Error 2
@rpq
rpq / gist:7282724
Created November 2, 2013 19:43
ruby-2.0.0-p247 fail compile
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -O1 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -ansi -std=iso9899:199409
XCFLAGS = -include ruby/config.h -include ruby/missing.h -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
CPPFLAGS = -I. -I.ext/include/x86_64-linux -I./include -I.
DLDFLAGS = -fstack-protector -pie
SOLIBS =
generating encdb.h
encdb.h unchanged
@rpq
rpq / gist:7282181
Created November 2, 2013 18:52
ruby 2.0 build fail
compiling pack.c
compiling parse.c
gcc: Internal error: Killed (program cc1)
Please submit a full bug report.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [parse.o] Error 1
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -ansi -std=iso9899:199409
@rpq
rpq / gist:6939503
Created October 11, 2013 18:16
ajax spinner and django header
3 /** setup spinner on ajax calls **/
4 $.ajaxSetup({
5 headers: { "HTTP_X_REQUESTED_WITH": "XMLHttpRequest" },
6 cache: false,
7 error: function() {
8 alert('There was an error reaching the server!');
9 },
10 timeout: 10000,
11 beforeSend: function() {
12 $('#loading-status').show();