Skip to content

Instantly share code, notes, and snippets.

View nfredrik's full-sized avatar
🎯
Focusing

Fredrik nfredrik

🎯
Focusing
View GitHub Profile
@nfredrik
nfredrik / temp.py
Last active July 19, 2022 16:16
temp
from datetime import datetime
temp34 = [34, 36, 38, 35, 29, 31]
spec_week = datetime.fromisocalendar(year=datetime.now().year, week=34, day=1)
day_in_month, month = int(spec_week.strftime("%d")), spec_week.strftime("%b").lower()
the_date = [f'{day} {month}' for day in range(day_in_month, day_in_month + len(temp34))]
for the_date, grader in zip(the_date, temp34):
print(f'{the_date}: {"*" * grader}')
@nfredrik
nfredrik / example.py
Created April 3, 2022 15:37 — forked from 1st1/example.py
asyncio queues example
import asyncio
import random
import time
async def worker(name, queue):
while True:
# Get a "work item" out of the queue.
sleep_for = await queue.get()
@nfredrik
nfredrik / datetime_range.py
Created January 27, 2022 15:04 — forked from obeattie/datetime_range.py
A datetime range class for Python, for (obviously) dealing with ranges of datetimes.
"""Provides a `DateTimeRange` class, which is used for managing ranges of datetimes."""
import datetime
class DateTimeRange(object):
"""Represents a range of datetimes, with a start and (optionally) an end.
Basically implements most of the methods on a standard sequence data type to provide
some lovely syntactic sugar. Specifically, you can iterate on this, index it, slice it,
use the in operator, reverse it, and use it in a boolean context to see if there is any
time in between the start and end."""
@nfredrik
nfredrik / debug_requests.py
Created December 15, 2021 14:43 — forked from Daenyth/debug_requests.py
Enable debug logging for python requests
import requests
import logging
import httplib
# Debug logging
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
req_log = logging.getLogger('requests.packages.urllib3')
req_log.setLevel(logging.DEBUG)
@nfredrik
nfredrik / validate_uuid4.py
Created October 30, 2021 06:23 — forked from ShawnMilo/validate_uuid4.py
Validating a uuid4 with Python.
from uuid import UUID
def validate_uuid4(uuid_string):
"""
Validate that a UUID string is in
fact a valid uuid4.
Happily, the uuid module does the actual
checking for us.
@nfredrik
nfredrik / ml-recs.md
Created October 16, 2021 18:44 — forked from bsletten/ml-recs.md
Machine Learning Path Recommendations

This is an incomplete, ever-changing curated list of content to assist people into the worlds of Data Science and Machine Learning. If you have a recommendation for something to add, please let me know. If something isn't here, it doesn't mean I don't recommend it, I just may not have had a chance to review it yet or not.

I will generally list things in order of easier to more formal/challenging content.

It may feel like there is an overwhelming amount of stuff for you to learn (because there is). But, there is a guided path that will get you there in time. You need to focus on Linear Algebra, Calculus, Statistics and probably Python (or R). Your best bet is to get a Safari Books Online account (https://www.safaribooksonline.com) which you may already have access to through school or work. If not, it is a reasonable way to get access to a tremendous number of books and videos.

I'm not saying you will get what you need out of everything here, but I have read/watched at least some of all of the following an

@nfredrik
nfredrik / chunked_server_test.py
Created January 19, 2021 20:44 — forked from josiahcarlson/chunked_server_test.py
Use some standard Python libraries to implement a chunked-transfer encoding web server with partially-working gzip support
'''
chunked_server_test.py
Copyright August 3, 2012
Released into the public domain
This implements a chunked server using Python threads and the built-in
BaseHTTPServer module. Enable gzip compression at your own peril - web
browsers seem to have issues, though wget, curl, Python's urllib2, my own
async_http library, and other command-line tools have no problems.
@nfredrik
nfredrik / Linsris_med_rokt_paprika_och_fankal.md
Created January 9, 2021 22:54 — forked from jonasryberg/Linsris_med_rokt_paprika_och_fankal.md
Jag köpte en tryckkokare. Nu samlar jag på mig bra vegetariska recept att laga till i den.

Linser och ris med smak av rökt paprika och fänkål

Det här receptet ger en rejäl laddning av linser och ris som passar bra att servera till tofu, ha i en wrap eller kanske bara till stekta grönsaker. Ursprungsreceptet hittade jag här.

Ingredienser

  • 400 gram gröna linser
  • 350 gram basmatiris (vitt)
  • 1 liter grönsaksbuljong
@nfredrik
nfredrik / note.dtd
Created September 26, 2020 06:23 — forked from wulftone/note.dtd
Simple xml-dtd validator
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
@nfredrik
nfredrik / fileutils_example.rb
Created September 26, 2020 06:14 — forked from jensendarren/fileutils_example.rb
An example of using FileUtils in Ruby
require 'fileutils'
# __FILE__ keyword in ruby
puts "The current ruby file being executed is #{__FILE__}"
# Gets the directory name of the file being executed
current_directory = File.dirname(__FILE__)
puts "The current directory is #{current_directory}"
# expands to reveal the pwd (Present working directory)