Skip to content

Instantly share code, notes, and snippets.

View isaquealves's full-sized avatar

Isaque Alves isaquealves

View GitHub Profile
@isaquealves
isaquealves / dict_group.py
Created April 10, 2015 05:02
Given a dictionary list, creates a new list with grouped dictionaries based on a single key (label) and summing the value of other dictionary fields as convenient
import itertools
item_list = [
{'counter1': 1, 'label': '20150408154801', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154801', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154801', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154819', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154819', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154819', 'counter2': 0, 'counter3': 0},
{'counter1': 1, 'label': '20150408154819', 'counter2': 0, 'counter3': 0},
@isaquealves
isaquealves / gist:aad1046307b9c6412e8d
Created May 9, 2015 05:56
Django new application loading
try:
from django.apps import apps
get_model = apps.get_model
except ImportError:
from django.db.models.loading import get_model
@isaquealves
isaquealves / .zshrc-with-rvm
Last active January 26, 2016 15:15
Runs common rvm commands using chpwd_functions from zsh. Add this to the end of .zshrc file. Runs on 'cd <directory>'
source ~/.zshrc
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
ORIGINAL_PATH=$PATH
function dev_env_setup() {
# see http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html
emulate -L zsh
@isaquealves
isaquealves / mongodb
Created January 3, 2017 23:43
If mongo db is refusing to start, lets kill him, force a repair, set proper ownership for db directory and then restart and check service status. Should be active.
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath=/var/lib/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo service mongod restart
sudo service mongod status
@isaquealves
isaquealves / .hgrc
Created April 7, 2017 20:12
Mercurial Alias to show detailed information about changes on the commit message file
[committemplate]
changeset = {desc}\n\n
HG: {extramsg}
HG: user: {author}\n{ifeq(p2rev, "-1", "",
"HG: branch merge\n")
}HG: branch '{branch}'\n{if(currentbookmark,
"HG: bookmark '{currentbookmark}'\n") }{subrepos %
"HG: subrepo {subrepo}\n" }
{splitlines(diff()) % 'HG: {line}\n'}
var Form = {
[...]
validate: function() {
var fields = this.form.querySelectorAll('input');
var self = this;
fields.forEach(function(element) {
if (self.formFields.indexOf(element.name) !== -1) {
var allowed = self.formFields[element.name].allow;
self.invalid[element.name] = matchValues(element, allowed);
}
@isaquealves
isaquealves / makemodule
Last active May 4, 2017 13:35
Script to ease add python modules to applications.
#!/bin/zsh
YES='y'
OPTIND=1
MODULE_NAME=''
filename=''
dirname=''
show_help() {
echo "Use this command with caution ;) (or not)"
syntax: glob
.codeclimate.yml
.editorconfig
*.orig
.vscode/*
*.todo
*.tasks
.jsbeautify*
jsprofiles/*
*.orig.*
#!/bin/sh
# this works for Bash and Zsh shell
a=("it is true for all that that that that that that that refers to is not the same that that that that refers to")
# Use this with Fish shell
# set a "it is true for all that that that that that that that refers to is not the same that that that that refers to"
# or if you need to count words in a sample file,
# cat <file> | tr " " "\n" | sort -n | uniq -c
@isaquealves
isaquealves / css-media-queries-cheat-sheet.css
Created September 26, 2018 15:24 — forked from bartholomej/css-media-queries-cheat-sheet.css
CSS Media Query Cheat Sheet (with Foundation)
/*------------------------------------------
Responsive Grid Media Queries - 1280, 1024, 768, 480
1280-1024 - desktop (default grid)
1024-768 - tablet landscape
768-480 - tablet
480-less - phone landscape & smaller
--------------------------------------------*/
@media all and (min-width: 1024px) and (max-width: 1280px) { }
@media all and (min-width: 768px) and (max-width: 1024px) { }