Skip to content

Instantly share code, notes, and snippets.

@kris-jusiak
kris-jusiak / bench_generators.cpp
Last active February 4, 2024 08:40
Simple generators benchmark
// https://godbolt.org/z/b9s5cxPao
#include <generator>
#include <utility>
auto generator_baseline() -> int {
static THREAD_LOCAL auto i = 0;
return i++;
}
@joao-timescale
joao-timescale / blog.py
Last active July 7, 2023 02:36
Blog example showing how to integrate pydantic with the peewee ORM
import pydantic
import peewee
from playhouse.db_url import connect
from typing import List
import logging
logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
@ematvey
ematvey / transforms.py
Last active September 18, 2018 08:50
Affine augmentations for 3D tensors targeted at medical images
import math
from typing import Union, NamedTuple
import numpy as np
from scipy.ndimage import affine_transform
class AffineTransform(NamedTuple):
matrix: np.ndarray
offset: np.ndarray
@boneskull
boneskull / README.md
Last active April 10, 2024 12:47
example of how to debug mocha v4 if hanging

Here's an example of how to debug Mocha v4 if it hangs.

Ensure you're using a Node.js 8 or newer (or any version with async_hooks support).

If you run your test, you'll notice it hangs:

$ mocha test.js
@tokestermw
tokestermw / self_attention.py
Last active June 29, 2022 05:39
Implementation of self-attention in the paper "Attention Is All You Need" in TensorFlow.
"""Example TensorFlow code for Self-Attention mechanism.
Refs:
Attention Is All You Need
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
https://arxiv.org/abs/1706.03762
Transformer: A Novel Neural Network Architecture for Language Understanding
https://research.googleblog.com/2017/08/transformer-novel-neural-network.html
@manujrastogi
manujrastogi / cognito-developer-authenticated-client-example.py
Created August 8, 2016 12:15 — forked from dkarchmer/cognito-developer-authenticated-client-example.py
django-boto3-cognito: AWS' Cognito Developer Authenticated Identities Authflow using Django/Python/Boto3 (For building stand-alone clients)
__author__ = 'dkarchmer'
'''
This script emulates a stand-alone Python based client. It relies on Boto3 to access AWS, but
requires your Django server to have an API for your user to access Cognito based credentials
Because of Cognito, the client (this script) will only get temporary AWS credentials associated
to your user and only your user, and based on whatever you configure your AIM Policy to be.
Most Cognito examples demonstrate how to use Cognito for Mobile Apps, so this scripts demonstrate
how to create a stand-alone Python script but operating similarly to these apps.
--use like eval(HRANDKEY, 2, key_for_set_with_keys, key_for_hash_with_keys)
local randkey = redis.call('srandmember', KEYS[1])
local val = redis.call('hget', KEYS[2], randkey)
return val
@vjpr
vjpr / README.md
Last active June 27, 2022 10:01
RPC for Chrome Packaged App to allow communication between sandbox and privileged environment

ChromeRPC

I will eventually turn this into a bower module when I have time with tests and the whole shebang.

Usage

background.html

@hfossli
hfossli / gist:7562257
Last active June 27, 2018 04:56
A bash script for fetching all branches and tags of a git project as snapshots into separate folders
#!/bin/bash
# Created by Håvard Fossli <[email protected]> in 2013
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
#
# Description
# A bash script for fetching all branches and tags of a git project as snapshots into separate folders
#
# Keywords
@tillahoffmann
tillahoffmann / performancemodule.c
Created January 17, 2012 14:53
A quick implementation of a trapezoidal convolution in C.
#include <Python.h>
//Normally #include "arrayobject.h" should be sufficient. I need to fix my includes.
#include "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h"
/*
* Convolution method.
*/
static PyObject* convolve(PyObject* self, PyObject* args)
{
PyArrayObject *vec1, *vec2, *conv; //The python object proxies