Skip to content

Instantly share code, notes, and snippets.

@0xregulus
0xregulus / filter.py
Created August 11, 2020 02:15
Useful Django template filters for handling JSON and for pretty print JSON in templates
import json
from django import template
register = template.Library()
@register.filter
def loadjson(data):
return json.loads(data)
@0xregulus
0xregulus / left_join_orm.py
Created April 10, 2019 16:32
Left Join Django 1.9
from django.db.models.sql.datastructures import Join
from django.db.models.fields.related import ForeignObject
from django.db.models.options import Options
from myapp.models import Ace
from myapp.models import Subject
jf = ForeignObject(
to=Subject,
on_delete=lambda: x,
from_fields=[None],
@0xregulus
0xregulus / __main__.py
Created September 22, 2017 17:45 — forked from drgarcia1986/__main__.py
Example of OAuth2 autentication server with Client Credentials grant (using python-oauth2 and tornado)
# !/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Diego Garcia'
import tornado.web
import tornado.ioloop
import oauth2.tokengenerator
import oauth2.grant
import oauth2.store.redisdb
import oauth2.store.mongodb
@0xregulus
0xregulus / snakecoin-server-full-code.py
Last active February 8, 2018 16:53 — forked from aunyks/snakecoin-server-full-code.py
The code in this gist isn't as succinct as I'd like it to be. Please bare with me and ask plenty of questions that you may have about it.
from flask import Flask
from flask import request
import json
import requests
import hashlib as hasher
import datetime as date
node = Flask(__name__)
# Define what a Snakecoin block is
class Block:
@0xregulus
0xregulus / rm_pyc
Created October 6, 2016 17:24
Remove all *.pyc
find . -name \*.pyc -delete
find . -name "*.pyc" -exec rm -rf {} \;
@0xregulus
0xregulus / keybase.md
Created March 14, 2016 13:51
keybase.md

Keybase proof

I hereby claim:

  • I am facundo-rodriguez-17 on github.
  • I am facundorodriguez (https://keybase.io/facundorodriguez) on keybase.
  • I have a public key whose fingerprint is 7715 7D55 D904 1393 EA76 D6B1 4E9E 021C 970C 9691

To claim this, I am signing this object:

@0xregulus
0xregulus / jaccard.py
Created October 6, 2015 00:02
w-shingling - for checking plagiarism
from __future__ import division
import itertools
import re
# a shingle in this code is a string with K-words
K = 4
def jaccard_set(s1, s2):
" takes two sets and returns Jaccard coefficient"
u = s1.union(s2)
@0xregulus
0xregulus / get_browser_version_os
Last active August 29, 2015 14:07
Get Web Browser, version and OS
function get_browser(){
var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem=/\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1]||'');
}
if(M[1]==='Chrome'){
tem=ua.match(/\bOPR\/(\d+)/)
if(tem!=null) {return 'Opera '+tem[1];}
}
@0xregulus
0xregulus / menu_launcher.py
Last active August 29, 2015 14:07 — forked from abishur/menu_launcher.py
TUI - Terminal User Interface
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.com/2010/03/python-curses-custom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code :-)
# Basic code refactoring by Andrew Scheller
from time import sleep
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho() # Disables automatic echoing of key presses (prevents program from input each key twice)