Skip to content

Instantly share code, notes, and snippets.

@onlyphantom
onlyphantom / gist:e2701ff038bf13a6a3826ab856205b59
Created January 30, 2025 14:56
DeepSeek R1's response to "how many primes are there between 7800 and 7920?"
# read the full article: https://sectors.app/bulletin/deepseek
Okay, the user is asking how many prime numbers exist between 7800 and 7920. Let me think through the steps needed to solve this.
First, I need to list all numbers in that range and check each for primality. But doing this manually would take too long. Maybe there's a smarter way. Primes are numbers greater than 1 that have no divisors other than 1 and themselves. So for each number in the range, I need to check if it's divisible by any prime number up to its square root.
Wait, the range is from 7800 to 7920. Let me note that the square root of 7920 is around 89, so I need to check divisibility by primes up to 89. The primes up to 89 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89. That's a lot, but manageable.
But maybe I can optimize. For even numbers, they are divisible by 2, so I can skip all even numbers except 2. Since the range starts at 7800, which is even, all even numbers can be excluded
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 January 23, 2025 17:01
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"),