Skip to content

Instantly share code, notes, and snippets.

View fried's full-sized avatar

Jason Fried fried

View GitHub Profile
@fried
fried / fibo.py
Created October 12, 2023 22:31
Lets generate fibonacci sequence until our harddrive fills up.
#### The Fibo generator
import math
import os
def fibo(a=0, b=1):
if a == 0 and b == 1:
skip = False
else:
skip = True
if not skip:
@fried
fried / test.py
Last active September 6, 2023 23:13
from enum import IntEnum
class Type(IntEnum):
String = 0
List = 1
Struct = 2
class Struct1:
@fried
fried / base.py
Created April 23, 2023 19:28
graphdb Assoc and Labels for test
from __future__ import annotations
import unittest
from contextlib import ExitStack
from enum import Enum
from pathlib import Path
from tempfile import TemporaryDirectory
from lmdb_graph import Assoc, FieldIndex, Graph, Label, field, frozen, register_enum
@fried
fried / query_test.py
Created April 23, 2023 19:16
Graphdb query syntax test
def test_kind_prop_nodes(self):
q = Query.n(Character, "chars", level=GTE(3))
self.assertEqual(type(q).__name__, "_PropNodeQuery")
nodes = list(q)
self.assertEqual(len(nodes), 3)
expected_results = [("guile", 5), ("ken", 4), ("ryu", 4)]
q = q.extract("chars.name", "chars.level")
self.assertEqual(type(q).__name__, "_ExtractedQuery")
results = list(q)
results.sort()
@fried
fried / test_task.py
Last active May 6, 2019 18:18
Testable asyncio task subclass
"""
When unittesting asyncio code, you should really check tasks
to see that you are not creating them and not checking them for results.
So you can get a set of tasks before and after the unittest runs,
then you need to be sure that somebody performed one of these operations
* await task
* task.result()
* task.exception()
@fried
fried / tarfilecopybuf
Created June 3, 2016 00:40
Benchmarch of Tarfile where you can set the copyfileobj bufsize beyond the default of 16k, using two random tar files of 1024 files each 10MB in size
Generating Random Test Tar Files................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@fried
fried / tarfiletestnotruncate
Last active June 3, 2016 00:46
Speeding up tarfile by not truncating on non-sparse tar entries. Using two random tar files of 1024 files each 10MB in size.
Generating Random Test Tar Files................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Keybase proof

I hereby claim:

  • I am fried on github.
  • I am revfried (https://keybase.io/revfried) on keybase.
  • I have a public key whose fingerprint is EB61 7397 1C29 3608 36C5 006B FC9F B5E1 214E E92B

To claim this, I am signing this object:

@fried
fried / bytes.hpp
Created September 10, 2014 20:55
from a mailing list post by arvid
// Copyright Arvid Norberg 2006-2013. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BYTES_HPP
#define BYTES_HPP
#include <string>
struct bytes
@fried
fried / libtorrent-python3
Last active August 29, 2015 14:06
libtorrent python3 patches and big_number hash function
diff libtorrent-rasterbar-0.16.16/bindings/python/src/big_number.cpp libtorrent/big_number.cpp
6a7,19
> #include "bytes.hpp"
>
> long getHash(boost::python::object o)
> {
> using namespace boost::python;
> return PyObject_Hash(str(o).ptr());
> }
>