Skip to content

Instantly share code, notes, and snippets.

@holgi
holgi / asyncio-mock-example.py
Created January 30, 2019 13:31
Example for mocking async context managers
import pytest
import aiohttp
import asyncio
from asynctest import CoroutineMock, MagicMock, patch
# Example Code
async def fetch(session, url):
@maltefiala
maltefiala / print2pdf.el
Last active September 28, 2022 10:23
emacs print-to-pdf on OSX
;; Adapted following script to OSX:
;; https://genomeek.wordpress.com/2013/03/08/emarch-2-create-a-pdf-with-highlighted-code-source/
(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "pstopdf tmp.ps -o " (buffer-name) ".pdf"))
(shell-command cmd)
@Miouyouyou
Miouyouyou / Linux_DRM_OpenGLES.c
Last active April 18, 2024 07:34
An example, inspired by Rob Clark "kmscube.c" that uses Linux Direct Rendering Manager ( DRM ) and EGL to create an OpenGL ES 2 context. This is a standalone example, that just clears the screen with a blueish color. Usable with Rockchip DRM drivers and Mali Wayland/DRM userspace drivers.
// gcc -o drmgl Linux_DRM_OpenGLES.c `pkg-config --cflags --libs libdrm` -lgbm -lEGL -lGLESv2
/*
* Copyright (c) 2012 Arvin Schnell <arvin.schnell@gmail.com>
* Copyright (c) 2012 Rob Clark <rob@ti.com>
* Copyright (c) 2017 Miouyouyou <Myy> <myy@miouyouyou.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
@akaIDIOT
akaIDIOT / periodic.py
Created March 26, 2015 21:26
Call something periodically using asyncio
import asyncio
def call_periodic(interval, callback, *args, **kwargs):
# get loop as a kwarg or take the default one
loop = kwargs.get('loop') or asyncio.get_event_loop()
# record the loop's time when call_periodic was called
start = loop.time()
def run(handle):
@dnmiller
dnmiller / GoogleTest.cmake
Last active April 21, 2019 10:08
CMake custom target for adding Python tests and GoogleTest unit tests to compiled libraries. Tests are run via nose.
# Custom cmake target for creating a target using gtest for unit testing.
function(add_gtest_target TARGET_NAME TARGET_LIB)
set(TEST_EXEC _${TARGET_LIB}_test)
# Build the test executable.
add_executable(${TEST_EXEC} ${ARGN})
target_link_libraries(${TEST_EXEC} ${TARGET_LIB})
# gtest was not found with a find_package command and must be linked to
@tuttlem
tuttlem / tree.hs
Created January 3, 2013 21:49
haskell - tree insert
singleton :: a -> Tree a
singleton x = Node x EmptyTree EmptyTree
treeInsert :: (Ord a) => a -> Tree a -> Tree a
treeInsert x EmptyTree = singleton x
treeInsert x (Node a left right)
| x == a = Node x left right
| x < a = Node a (treeInsert x left) right
| x > a = Node a left (treeInsert x right)
@nschum
nschum / gist:2626303
Created May 7, 2012 06:44
better "enum class" indent in Emacs
;; This hack fixes indentation for C++11's "enum class" in Emacs.
;; http://stackoverflow.com/questions/6497374/emacs-cc-mode-indentation-problem-with-c0x-enum-class/6550361#6550361
(defun inside-class-enum-p (pos)
"Checks if POS is within the braces of a C++ \"enum class\"."
(ignore-errors
(save-excursion
(goto-char pos)
(up-list -1)
(backward-sexp 1)
@tomykaira
tomykaira / camelize.el
Created February 13, 2012 04:40
camelize.el --- Make a string from snake_case to CamelCase
;;; camelize.el --- Make a string from snake_case to CamelCase
;; Copyright (C) 2012 tomykaira
;; Author: tomykaira <tomykaira@gmail.com>
;; Keywords: emacs
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
@chrisroos
chrisroos / gpg-import-and-export-instructions.md
Created September 9, 2011 10:49
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...