Skip to content

Instantly share code, notes, and snippets.

View rlcarrca's full-sized avatar

Robert Carr rlcarrca

View GitHub Profile
@rlcarrca
rlcarrca / basic_auth_server.py
Created August 3, 2015 01:21
Doing basic authentication in bottle.
import bottle
def check(user, passwd):
if user == 'ben':
return True
return False
@bottle.route('/')
@bottle.auth_basic(check)
def index(location):
@rlcarrca
rlcarrca / basic_auth_check.py
Created August 3, 2015 01:22
Checking basic authentication
import urllib2, base64
(user, password) = ('ben', 'xyz')
request = urllib2.Request("http://localhost:8080/")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
print result.read()
@rlcarrca
rlcarrca / s3.sh
Created December 20, 2015 15:33 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@rlcarrca
rlcarrca / new_task.py
Created April 16, 2016 20:29
Multiprocessing sample with RabbitMQ
#!/usr/bin/env python
import sys
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello', durable=True)
@rlcarrca
rlcarrca / get_metadata.sh
Last active May 6, 2023 03:57
RETS server connectivity via curl
curl \
--digest \
--user-agent "MyCurlClient/1.0" \
-o data/metadata.xml \
--show-error \
--dump-header data/headers.txt \
-u "username:password" \
--header "RETS-Version: RETS/1.5" \
--cookie-jar data/cookies.txt \
--cookie data/cookies.txt \
'''
Determination of the day of the week
Jan 1st 1 AD is a Monday in Gregorian calendar.
So Jan 0th 1 AD is a Sunday [It does not exist technically].
Every 4 years we have a leap year. But xy00 cannot be a leap unless xy divides 4 with reminder 0.
y/4 - y/100 + y/400 : this gives the number of leap years from 1AD to the given year. As each year has 365 days (divdes 7 with reminder 1), unless it is a leap year or the date is in Jan or Feb, the day of a given date changes by 1 each year. In other case it increases by 2.
y -= m<3 : If the month is not Jan or Feb, we do not count the 29th Feb (if it exists) of the given year.
So y + y/4 - y/100 + y/400 gives the day of Jan 0th (Dec 31st of prev year) of the year. (This gives the reminder with 7 of the number of days passed before the given year began.)
Go to: chrome://settings/searchEngines
Add a new search engine with the following settings
Gif | Gif | https://www.google.com/search?q=%s&tbm=isch&tbs=itp:animated
Type gif in the address bar press TAB and enter your search query
import sys
from boto.sqs.connection import SQSConnection
conn=SQSConnection('AWS_ACCESS_KEY_ID','AWS_SECRET_KEY')
q=conn.get_queue(sys.argv[1])
attrib = q.get_attributes("ApproximateNumberOfMessages")
print int(attrib['ApproximateNumberOfMessages'])
@rlcarrca
rlcarrca / librets_install.txt
Created June 18, 2017 01:02 — forked from dmpeters/librets_install.txt
librets installations with python bindings only
# Debian 7 x64, Ubuntu 14.04 x64, Ubuntu 12.04.4 x64
*NOTE (tested on Digital Ocean VM's w/ > 512MB of RAM - gcc runs out of memory on VM's <= 512 MB)
apt-get update
aptitude safe-upgrade
apt-get install build-essential libboost-all-dev libcurl4-gnutls-dev autoconf antlr swig python-dev
*NOTE (for python 3 support add 'python3-dev' to the end of line 5)
cd /tmp
wget https://github.com/NationalAssociationOfRealtors/libRETS/archive/1.6.1.tar.gz
@rlcarrca
rlcarrca / auth.py
Created August 18, 2017 21:58 — forked from ibeex/auth.py
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%s@xxx.xx' % username