Skip to content

Instantly share code, notes, and snippets.

@wladston
wladston / dcmst.py
Created Mar 5, 2012
Degree constrained minimum spanning tree with networkx
View dcmst.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
# This is the framework for graphs we use on this work
import networkx as nx
# Tool to determine wether elements are on the same set
from networkx.utils import UnionFind
# We need this in python to "clone" objects
import copy
@wladston
wladston / strip_database.py
Created Feb 6, 2013
Strip all strings that exist in a MongoDB database. It will work recursively to strip **ALL** your strings. Binary data won't be affected.
View strip_database.py
# -*- coding: utf-8; -*-
from bson import Binary
from pymongo import Connection
from pymongo.database import Database
db = Database(Connection(), "yourdb")
def _clean_dict(x):
dic = {}
View custom-submit.js
/**
* Custom submit directive that will only submit when all the validation has passed
* for all the fields. This extends on the ng-submit directive provided by AngularJS.
*
* This directive will also remove the 'pristine' flag from all the fields when
* hitting submit, allowing the form to display no errors until the submit button
* is clicked/enter is pressed.
*
* The variable 'app' is the instance of a module.
* E.g. var app = angular.module('my-app', []);
@wladston
wladston / humanize_time.py
Created May 24, 2013
Python relative time
View humanize_time.py
from datetime import datetime, timedelta
from dateutil import relativedelta
from datetime import datetime
from dateutil.tz import tzutc, tzlocal
def humanize_time(time):
'''
get a datetime object and return a relative time string like
"one hour ago", "yesterday", "3 months ago", "just now", etc.
@wladston
wladston / distcorr.py
Last active Dec 25, 2020
Distance correlation with p-value
View distcorr.py
from scipy.spatial.distance import pdist, squareform
import numpy as np
import copy
def distcorr(Xval, Yval, pval=True, nruns=500):
""" Compute the distance correlation function, returning the p-value.
Based on Satra/distcorr.py (gist aa3d19a12b74e9ab7941)
>>> a = [1,2,3,4,5]
@wladston
wladston / pt.utf-8.spl
Last active Aug 29, 2015
Arquivo de correção ortográfica do VERO, v3.2
View pt.utf-8.spl
This file has been truncated, but you can view the full file.
View keybase.md

Keybase proof

I hereby claim:

  • I am wladston on github.
  • I am wlad (https://keybase.io/wlad) on keybase.
  • I have a public key whose fingerprint is F19A E5A4 CB44 5708 0258 104B 57C2 4F99 7623 27EE

To claim this, I am signing this object:

View gist:a5ac098091439fc03796cb0ddc363162
Verifying that +wladston is my blockchain ID. https://onename.com/wladston
@wladston
wladston / critic_to_tex.py
Created Aug 24, 2016
This converts <http://criticmarkup.com/> tags in a Markdown file to "equivalent" LaTex formatting.
View critic_to_tex.py
#!/usr/bin/python
# This converts <http://criticmarkup.com/> tags in a Markdown file to
# "equivalent" LaTex formatting.
#
# By Wladston Filho <wlad@code.enegy>
import sys
import re