Skip to content

Instantly share code, notes, and snippets.

View fmartingr's full-sized avatar

Felipe Martin fmartingr

View GitHub Profile
@fmartingr
fmartingr / initial_data.json
Last active October 6, 2015 05:37
django initial fixture file with admin user: admin/1234
[
{
"model": "auth.user",
"pk": 1,
"fields": {
"first_name": "John",
"last_name": "Doe",
"username": "admin",
"email": "[email protected]",
"password": "pbkdf2_sha256$10000$VVJjeNI4DX0Z$dI0w6zSkvvFO+B7s9+rxVS0sj6N2Tp/xVny3FokWQis=",
def pid_exists(pid):
"""Check whether pid exists in the current process table."""
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError, e:
return e.errno == errno.EPERM
else:
return True
@fmartingr
fmartingr / echo.py
Last active November 19, 2022 10:47
Custom print function in python with colors.
from sys import stdout
class Colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
@fmartingr
fmartingr / Rakefile
Created December 5, 2012 15:55 — forked from jarrettmeyer/Rakefile
Octopress publish drafts
require "rubygems"
require "date"
# Configuration
base_dir = Dir.pwd
blog_dir = "#{base_dir}/blog"
source_dir = "#{blog_dir}/source"
posts_dir = "#{source_dir}/_posts"
git_remote = "origin"
git_branch = "master"
@fmartingr
fmartingr / hash.php
Created January 14, 2013 16:08
Encryption types comparision in PHP
<?
$data = "Hash cheching!";
echo '<pre>';
printf("%-12s %6s %11s %s\n", "Hash name", "Lenght", "Time", "Hash");
foreach (hash_algos() as $hash_type) {
$start = microtime(true);
$hash = hash($hash_type, $data, false);
$end = microtime(true);
$elapsed = number_format($end - $start, 6);
printf("%-12s %6d %10fs %s\n", $hash_type, strlen($hash), $elapsed, $hash);
@fmartingr
fmartingr / dataset-models.py
Last active December 18, 2015 02:58
Little model objects using the dataset framework: https://dataset.readthedocs.org/en/latest/index.html
# Imports
import dataset
###
# CONFIG
###
DATABASE_URL = 'sqlite:///' # In memory database
###
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
import sys
import os
import re
import hotshot, hotshot.stats
import tempfile
import StringIO
@fmartingr
fmartingr / form.coffee
Created August 21, 2013 14:03
Class to manage dynamic forms with coffeescript
class Form
###
Class to manage dynamic forms with javascript
> var form = Form('/destiny/path/', {'username':'fmartingr'})
> form.addField('password', 'aw8cnwn8t7x9my898wyf9mw67n')
> form.submit()
###
constructor: (action, params={}, method='post') ->
@fmartingr
fmartingr / django_cms.py
Created December 4, 2013 12:33
Fixes for certain projects
def fix_contentype_pages():
"""
Fix admin recent history name value for django-cms pages
"""
from django.contrib.contenttypes.models import ContentType
items = ContentType.objects.filter(model='page', name='', app_label='cms')
for item in items:
item.name = 'page'
item.save()
### Keybase proof
I hereby claim:
* I am fmartingr on github.
* I am fmartingr (https://keybase.io/fmartingr) on keybase.
* I have a public key whose fingerprint is CDCC 52FA FE1A 5CC4 6809 E76E 7975 4701 665A 55CB
To claim this, I am signing this object: