Skip to content

Instantly share code, notes, and snippets.

View miceno's full-sized avatar

Orestes Sanchez miceno

  • Barcelona, Spain
View GitHub Profile
@miceno
miceno / json-number.sh
Created December 27, 2017 12:30
Extract number value from json
echo '{"count":7363,"_shards":{"total":1,"successful":1,"failed":0}}' | sed -e 's/^.*"count":\([^,]*\),.*$/\1/'
@miceno
miceno / rsync.sh
Created October 29, 2017 17:56
Rsync remote
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress SOURCE HOST:TARGET
@miceno
miceno / .gitignore
Last active March 22, 2019 20:16
Postgresql scripts
.idea
@miceno
miceno / crontab.sh
Created December 26, 2016 01:29
Crontab debugging
Add
* * * * * env > ~/cronenv
to your crontab, let it run once, turn it back off, then run
env - `cat ~/cronenv` /bin/sh
And you are now inside a sh session which has cron's environment
@miceno
miceno / count.py
Created June 3, 2016 08:05
Aggregated count of categories
# Models
# ColourLabel
# name
#
# Ingredient
# name
# ColourLabelRelation
#
# ColourLabelRelation
@miceno
miceno / import.py
Last active January 2, 2020 18:30 — forked from bmihelac/import.py
Import management command for django-import-export
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import mimetypes
import argparse
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from django.core.management.base import BaseCommand
from django.db import transaction
@miceno
miceno / manual-export.py
Created May 11, 2016 14:43
Hand-Manual CSV export
import csv
from ingredients.models import Ingredient
f = csv.writer(open('ing-colors.out','wb'))
f.writerows(Ingredient.objects.filter(
dataset__name="multinet").values_list(
'ingredientdataset__engine_id',
'colour_dominant',
'colour_palette'))
@miceno
miceno / mock_open_with_files.py
Created November 29, 2015 19:32 — forked from romanlevin/mock_open_with_files.py
Mock out the contents of several files with a single patch
from mock import MagicMock
def mock_open_with_files(files):
"""
`files` - a dictionary of the form
{
'/file/path/': 'file body',
...
}
"""
@miceno
miceno / screenrc
Created September 30, 2015 10:51
Screenrc configuration
startup_message off
hardstatus on
hardstatus alwayslastline
# Show current terminals and time
hardstatus string "%{.bW}%-w%{..G}%n %t%{-}%+w %=%{..G} %H %{..Y} %d/%m %C%a"
# allow scrolling
@miceno
miceno / README.md
Last active September 27, 2015 17:26
Email confirmation on Wordpress Contact Form 7

This is a way to validate email by double email fields. Validation is via Javascript.

Files layout is:

../your-child-theme
    |- functions.php
    |- js/email-confirm.js