Skip to content

Instantly share code, notes, and snippets.

@faruken
faruken / fibonacci.py
Created December 21, 2017 11:42
lol fibonacci
def fibonacci(n):
i = 1
while (((i & 0xffff0000) >> 16) + (i & 0xffff) <= 0xffff):
print '%d' % (i & 0xff),
i = ((i & 0xffff) << 16) | ((i >> 16) + (i & 0xffff))
if __name__=='__main__':
fibonacci(10)
@faruken
faruken / s3arangodb.sh
Created July 21, 2017 04:14
backup arangodb to S3
#!/bin/sh
# Slightly modified to meet ArangoDB's needs. https://github.com/lumerit/s3-shell-backups
NOWDATE=`date +%Y-%m-%d`
LASTDATE=$(date +%Y-%m-%d --date='1 week ago')
USERNAME="${ARANGODB_USERNAME}"
PASSWORD="${ARANGODB_PASSWORD}"
DATABASE='dbname'
@faruken
faruken / letsencrypt_2016.md
Created January 10, 2017 05:35 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two modes when you don't want Certbot to edit your configuration:

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80) to renew certificates.

In the following, we're setting up mydomain.com to be served from /var/www/mydomain, and challenges will be served from /var/www/letsencrypt.

@faruken
faruken / memoization_fibo.py
Created October 8, 2012 18:32
Memoization - Fibonacci numbers example
def memoize(func):
cache = {}
def wrapper(*args):
try:
return cache[args]
except:
result = func(*args)
cache[args] = result
return result
return wrapper
@faruken
faruken / lol.py
Created July 25, 2012 05:54
Flask running behind Twisted
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from twisted.application import service
from twisted.web import server, static
from twisted.web.resource import Resource
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
from flask.views import MethodView
@faruken
faruken / add.html
Created July 16, 2012 03:44
Flask meets web.py
<form action="{{url_for('add')}}" method="post">
<p><label for="title">title:</label><input type="text" name="title" id="title"/></p>
<p><label for="text">text</label><input type="text" name="text" id="text"/>
</p>
<p><input type="submit" value="send"/></p>
</form>
@faruken
faruken / imgur.py
Created June 27, 2012 12:17
A quick hack on downloading imgur albums with gevent!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
import sys
import os
import urllib2
from urlparse import urlparse
import random
import re
@faruken
faruken / form.py
Created September 13, 2011 05:20
web.py's form.py HTML5 forms features.
"""
HTML forms
(part of web.py)
"""
import copy, re
import webapi as web
import utils, net
def attrget(obj, attr, value=None):
@faruken
faruken / hello.py
Created September 13, 2011 05:15
fibonacci numbers with dynamic programming
def memoize(func):
cache = {}
def wrapper(*args):
try:
return cache[args]
except:
result = func(*args)
cache[args] = result
return result
return wrapper