Skip to content

Instantly share code, notes, and snippets.

View VITIMan's full-sized avatar

Victoriano Navarro VITIMan

View GitHub Profile

Keybase proof

I hereby claim:

  • I am vitiman on github.
  • I am vitiman (https://keybase.io/vitiman) on keybase.
  • I have a public key whose fingerprint is 1509 C29C 34BF A349 D33C 4BF5 00A9 75A0 96BE E609

To claim this, I am signing this object:

@VITIMan
VITIMan / date_range_iterator.py
Last active August 23, 2017 14:00
Date Range Iterator in minutes
# python imports
import datetime
RANGE_TIME = 15
def date_range_iterator(start_date, end_date, delta=None):
""" Iterator for date ranges, given an start_date, end_date and an
optional delta (the range)
@VITIMan
VITIMan / waitrequests.js
Last active November 3, 2015 08:52
Jquery :: Wait until all requests are done
var requests = [];
Object.keys(sources).forEach(function(key){
requests.push(someAjaxAsyncRequest(arguments));
});
$.when.apply($, requests).done(function() {
console.log(arguments);
$.each(arguments, function (i, data) {
// By method
console.log(data);
});
@VITIMan
VITIMan / tmux.cheat
Created March 10, 2016 14:04 — forked from afair/tmux.cheat
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &
@VITIMan
VITIMan / README.md
Created May 11, 2016 15:26 — forked from LastDragon-ru/README.md
git-http-backend + nginx (RHEL/Centos)

Requirements:

  • fcgiwrap
  • spawn-fcgi
  • nginx
  • git

Repository setup (without anonymous access):

@VITIMan
VITIMan / server-git.conf
Created May 11, 2016 15:30 — forked from massar/server-git.conf
Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
# Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
# [email protected] - http://jeroen.massar.ch
server {
listen 192.0.1.1:80;
listen [2001:db8::1]:80;
# Redirect all non-HTTPS traffic to the HTTPS variant
return 301 https://$host$request_uri;
}
@VITIMan
VITIMan / chunk.py
Created August 10, 2017 12:35
Different options to chunk sequences or iterables
from itertools import chain, islice, zip_longest
# izip_longest in python2
def grouper(iterable, n, fillvalue=None):
"""
# https://stackoverflow.com/a/434411
>>> aaa = [1, 2, 3, 5, 6, 1, 3, 4, 8, 2094283, 123]
>>> [_ for _ in grouper(aaa, 3)]
[(1, 2, 3), (5, 6, 1), (3, 4, 8), (2094283, 123, None)]
@VITIMan
VITIMan / flask_download_file.py
Last active July 26, 2020 19:59
Flask snippets
def download_file():
"""
http://code.runnable.com/UiIdhKohv5JQAAB6/how-to-download-a-file-generated-on-the-fly-in-flask-for-python
"""
...
some_text = ""
filename = "FILENAME"
response = make_response(some_text, 200)
response.content_type = "text/plain"
response.headers[
@VITIMan
VITIMan / comparing_two_fields.py
Last active January 3, 2018 15:10
PyMongo snippets
def reaching_max_messages(current_hour_bitrange):
"""
from https://stackoverflow.com/a/29281409
"""
# https://stackoverflow.com/a/29281409
# https://docs.mongodb.com/manual/reference/operator/query/bitsAllSet/
pipeline = [
{
@VITIMan
VITIMan / random_snippets.py
Created August 10, 2017 13:32
Snippets using random library
import random
import string
def _random_string(N, chars=string.ascii_uppercase + string.digits):
""" To generate values from a set of chars and a given length
"""
return ''.join(random.choice(chars) for _ in range(N))