Skip to content

Instantly share code, notes, and snippets.

@juandebravo
juandebravo / expiration_time_firebase_custom_token.py
Created June 11, 2020 08:45
Firebase auth: change the custom token expiration time
import functools
import datetime
import time
from firebase_admin import auth
import google.auth.exceptions
EXP_TIME_GENERIC_TOKEN = int(datetime.timedelta(minutes=15).total_seconds())
RESERVED_CLAIMS = set([
@juandebravo
juandebravo / install_vbox_guest_additions.sh
Created January 10, 2016 00:56
Install VirtualBox guest additions
# Steps taken from official documentation:
#
# https://docs.vagrantup.com/v2/virtualbox/boxes.html
#
# If you get this message while launching a Vagrant box:
shell> vagrant up
# ...
#
# Failed to mount folders in Linux guest. This is usually because
# the "vboxsf" file system is not available. Please verify that
@juandebravo
juandebravo / encodings.py
Created August 3, 2013 23:23
Check the representation of a set of characters using different encodings
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) > 1:
code_points = [unicode(c, 'utf-8') for c in sys.argv[1:]]
else:
# Testing values
code_points = [u'\U0001F37A\U00000045\U0000039B', u'\U0001F37A']
#code_points = [unicode('❯❯', 'utf-8')]
class Foo
class << self
attr_accessor :configuration
def config(value=nil)
if block_given?
yield configuration
elsif value
configuration[value]
else
configuration
@juandebravo
juandebravo / get_user_gists.py
Created July 16, 2012 19:52
Retrieve user gists using a generator
import sys
import json
import requests
import re
from urlparse import urlparse, parse_qs
GITHUB_URL = 'https://api.github.com'
GIST_URL = GITHUB_URL + "/users/{0}/gists"
@juandebravo
juandebravo / gist:3103575
Created July 13, 2012 08:16
juandebravo.zsh-theme
PROMPT='$(machine_name) [%~]$(rvm_prompt_info)$(nvm_prompt_info)$(python_prompt_info) $(git_prompt_info) %{$reset_color%}
%{$fg[red]%}λ %{$reset_color%}'
machine_name() {
#echo "%{$fg[blue]%}%n%{$fg[magenta]%}->%{$fg[blue]%}%m%{$reset_color%}"
echo "%{$fg[blue]%}%m%{$reset_color%}"
}
rvm_prompt_info() {
rvm_info=$(rvm-prompt i v g 2> /dev/null)
@juandebravo
juandebravo / gist:3103566
Created July 13, 2012 08:14
gitconfig_example
[user]
name = <username>
email = <email>
[alias]
lg= log --graph --abbrev-commit --date=relative --all
co = checkout
br = branch
ci = commit
st = status
unstage = reset HEAD --
@juandebravo
juandebravo / cpython_json_cjson_pickle.py
Created April 4, 2012 22:12
cpython_json_cjson_pickle
import time
import cPickle as pickle
import json
import cjson
import ujson
d = {
'foo': 'bar',
'food': 'barf',
'good': 'bars',
@juandebravo
juandebravo / gist:2199750
Created March 25, 2012 21:05
client validation
obj = ParamsValidator::Request.new
obj[:data] = "this is a log"
obj[:level] = 1
ruleset = MockObject.get_rule(:method2)
obj.valid?(ruleset) # false
begin
obj.validate(ruleset)
rescue ArgumentError => ae
p ae.message # array with validation errors
end
@juandebravo
juandebravo / main_re.py
Created February 7, 2012 23:35
Cast CamelCase to "underscore_case"
import re
import json
def add_underscore(letter):
return "_"+letter.group(0).lower()
def to_lower(letter):
return letter.group(0).lower()
def cast_to_underscore_case(value):