Skip to content

Instantly share code, notes, and snippets.

from django.db.models import Sum
from core.services.main.finance import FinanceSvc
from core.models import ShiftAssignment
import arrow
finance_svc = FinanceSvc()
branch_id = 563
month_date = "2019-04-01 00:00"
a_month_date = arrow.get(month_date)
@henocdz
henocdz / zip_write_dir.py
Last active September 21, 2018 00:50
Write files from folder recursively into ZIPFile object
def zip_write_dir(zip_fileobj, dir_path, files_prefix=''):
for dirpath, dirnames, dirfiles in os.walk(dir_path):
for dirname in dirnames:
if files_prefix:
dir_prefix = '%s/%s' % (files_prefix, dirname)
else:
dir_prefix = dirname
dir_path = os.path.join(dirpath, dirname)
zip_write_dir(zip_fileobj, dir_path, files_prefix=dir_prefix)
@henocdz
henocdz / aliases.sh
Last active September 20, 2018 14:06
# REACT NATIVE
alias rnlios="react-native log-ios"
# DJANGO
alias djmm="python manage.py makemigrations"
alias djm="python manage.py migrate"
alias djrun="python manage.py runserver 0.0.0.0:8000"
alias pm="python manage.py"
alias pmt="python manage.py test"

Given an array strings, determine whether it follows the sequence given in the patterns array. In other words, there should be no i and j for which strings[i] = strings[j] and patterns[i] ≠ patterns[j] or for which strings[i] ≠ strings[j] and patterns[i] = patterns[j].

Example

For strings = ["cat", "dog", "dog"] and patterns = ["a", "b", "b"], the output should be areFollowingPatterns(strings, patterns) = true; For strings = ["cat", "dog", "doggy"] and patterns = ["a", "b", "b"], the output should be areFollowingPatterns(strings, patterns) = false.

import re
from collections import OrderedDict
import requests
import numpy
import matplotlib.pyplot as plot
def compute_list_score(list_id, members_ids):
cards_url = 'https://api.trello.com/1/lists/{}/cards?fields=all&token=[TOKEN]&key=[KEY]'.format(list_id)
# I was folling this tutorial http://gettechtalent.com/blog/tutorial-real-time-frontend-updates-with-react-serverless-and-websockets-on-aws-iot.html
# but I didn't like the idea of a lambda function just for presigned URL if we already have an API that could handle this
# but... there is no Python package that does ONLY this presigned url generation
# so I decided to "translate" the code of npm package 'aws-signature-v4' (https://git.department.se/department/aws-signature-v4.git) to Python
# probably there are bugs as I only have test it with my specific params.
import urllib.parse
import hmac
import hashlib
from datetime import datetime
@henocdz
henocdz / fibos.py
Created October 25, 2017 02:38
Fibos
def get_input(cast, text=''):
"""Request user for input and tries to cast input to cast function provided
Args:
cast (function): cast function to use
text (string): text to print so user can know what to type in!
Returns:
casted user input
"""
try:
return cast(input(text))
@henocdz
henocdz / app.jsx
Last active October 25, 2017 02:37
React Router v4 "Static Routes"
import React from 'react'
import ReactDOM from 'react-dom'
import { createBrowserHistory } from 'history'
import { ConnectedRouter } from 'react-router-redux'
// Global Styles
import 'styles/app.less'
// Routes config

Keybase proof

I hereby claim:

  • I am henocdz on github.
  • I am henocdz (https://keybase.io/henocdz) on keybase.
  • I have a public key whose fingerprint is 9C96 DF24 FE61 35E6 2417 5AD4 43F4 8594 1C29 ADD7

To claim this, I am signing this object:

@henocdz
henocdz / download_http.py
Last active February 10, 2017 21:11
A Django download HTTP response class that forces download in the browser.
from django.http import HttpResposne
import os
class DownloadResponse(HttpResponse):
"""
A download HTTP response class that forces download in the browser or redirects to URL given for file.
Args: