Skip to content

Instantly share code, notes, and snippets.

import time
import numpy as np
def timeit():
"""
a utility decoration to time running time
"""
def decorator(func):
def wrapper(*args, **kwargs):
@onlyphantom
onlyphantom / gist:ab4259c56bd031339d5c14b42048b0f7
Created March 21, 2022 06:04
Samuel's taskwarrior configuration file
# [Created by task 2.5.1 3/9/2022 15:39:38]
# Taskwarrior program configuration file.
# For more documentation, see http://taskwarrior.org or try 'man task', 'man task-color',
# 'man task-sync' or 'man taskrc'
# Here is an example of entries that use the default, override and blank values
# variable=foo -- By specifying a value, this overrides the default
# variable= -- By specifying no value, this means no default
# #variable=foo -- By commenting out the line, or deleting it, this uses the default
@onlyphantom
onlyphantom / gist:23459b117ca45337bab7ea0398a8c45a
Last active September 26, 2021 06:55
Industry / Selector field for django (list of tuple)
INDUSTRIES = (
('' , _('Select Industry / Sector')),
('accounting', _('Accounting')),
('airlines', _('Airlines/Aviation')),
('alternative_medicine', _('Alternative Medicine')),
('analytics_data', _('Analytics / Data Science')),
('animation', _('Animation')),
('apparel', _('Apparel/Fashion')),
('architecture', _('Architecture/Planning')),
('arts', _('Arts/Crafts')),
1. Ayu Nur Indahsari
2. Fatia Bani Ulfah
3. Gede Ocha Dipa Ananda
4. Henrico Aldy Ferdian
5. Stane Aurelius Ronotana
6. Vincentius Christopher Calvin
@onlyphantom
onlyphantom / querysets.md
Last active October 8, 2023 19:53
QuerySet API Reference (with code examples)

QuerySet API reference (stock portfolio example)

An in-depth guide to Django QuerySet (Django 3.0, updated June 2020).

When QuerySets are evaluated

Internally, a QuerySet can be constructed, filtered, sliced, and generally passed around without actually hitting the database. No database activity actually occurs until you do something to evaluate the queryset. Examples of that "something" that cause a QuerySet to evaluate:

  1. Iteration: QuerySet executes its database query the first time you iterate over it
    for q in Quote.objects.all():
        print(q.symbol)
@onlyphantom
onlyphantom / docker-volumes.md
Last active April 2, 2024 20:49
Demystifying Docker Volumes for Mac and PC Users

Demystifying Docker Volumes for Mac and PC Users

  1. Docker runs on a Linux kernel

Docker can be confusing to PC and Windows users because many tutorials on that topic assume you're using a Linux machine.

As a Linux user, you learn that Volumes are stored in a part of the host filesystem managed by Docker, and that is /var/lib/docker/volumes. When you're running Docker on a Windows or Mac OS machine, you will read the same documentation and instructions but feel frustrated as that path don't exist on your system. This simple note is my answer to that.

When you use Docker on a Windows PC, you're typically doing one of these two things:

  • Run Linux containers in a full Linux VM (what Docker typically does today)
@onlyphantom
onlyphantom / keybase.md
Created September 14, 2019 08:56
keybase authentication

Keybase proof

I hereby claim:

  • I am onlyphantom on github.
  • I am onlyphantom (https://keybase.io/onlyphantom) on keybase.
  • I have a public key ASDF7qQEOH0LG61XHuZmjod-7sXwdVzHFuw6rbaGfHyRdAo

To claim this, I am signing this object:

@onlyphantom
onlyphantom / validate_repo.py
Last active May 24, 2019 10:51
Regex to capture GitHub username/repo slug
# for username:
# Username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen
# for repo url:
# any valid alphanumeric including underscores
import re
def validate_repo_url(value):
reg = re.compile('^([a-zA-Z\d]{1}[-a-zA-Z\d]+)(/){1}([\-\w]+)$')
@onlyphantom
onlyphantom / sqlserver.R
Created June 16, 2018 15:33
Sample Code: Using SQL Server with Microsoft R
sqlConnString <- "Driver=SQL Server;Server=SETHMOTTDSVM;Database=RDB;Uid=ruser;Pwd=ruser"
# read in chunks of 100000
sqlRowsPerRead <- 100000
sqlTable <- "NYCTaxiBig"
ccColInfo <- list(
tpep_pickup_datetime = list(type = "character"),
tpep_dropoff_datetime = list(type = "character"),
passenger_count = list(type = "integer"),
trip_distance = list(type = "numeric"),