Skip to content

Instantly share code, notes, and snippets.

View rileymjohnson's full-sized avatar

Riley Johnson rileymjohnson

  • UNC Chapel Hill
  • Chapel Hill, NC
View GitHub Profile
//
//Registry.cpp
//
//Implementation for DllRegisterServer,DllUnregisterServer
//Contains code to write COM server data into the registry and
//also removing the data that had been written into the registry
//by this module.
//
#include <windows.h>
@rileymjohnson
rileymjohnson / winrt_load_dll_without_registration.cpp
Last active August 30, 2023 12:22
Load a WinRT component from a DLL without registration
#include <winrt/base.h>
#include <type_traits>
#include <hstring.h>
template <typename T>
winrt::impl::com_ref<T> load_winrt_component_from_dll(const winrt::hstring& dll_file)
{
WINRT_ASSERT(std::is_base_of_v<winrt::Windows::Foundation::IUnknown, T>, "T must inherit from Windows::Foundation::IUnknown");
INT32(__stdcall * get_activation_factory)(void*, void**) { nullptr };
@rileymjohnson
rileymjohnson / hash_file.py
Created March 22, 2023 19:52
Hash a file in Python using sha256 and memoryview
from path import Pathlib
import hashlib
def hash_file(file: str | Path) -> str:
sha256 = hashlib.sha256()
file_mem_view = memoryview(
bytearray(128 * 1024)
)
@rileymjohnson
rileymjohnson / pdfjs_letter_position_extraction.js
Created March 22, 2023 19:51
Extra the letters of a PDF document and their positions
/*
When loading the PDF document, you need to set the `fontExtraProperties` parameter to `true`. e.g.
getDocument({
...,
fontExtraProperties: true
})
*/
var generateId = () => {
return (
import torch
layer = torch.nn.Conv2d(128, 256, kernel_size=(2, 2), stride=(3, 3), padding=(1, 1))
for i in range(5, 21):
z = torch.zeros(1, 128, i, i)
z = layer(z)
print(z.shape)
@rileymjohnson
rileymjohnson / workProcessor.php
Created August 29, 2018 13:02
Bibtex work parser that lowercase's properties
/*
this is a snippet of the class that does this processing
*/
foreach ($bibliography as &$work){
foreach ($work as $key => $value) { //iterates over the properties of the work (an individual citation) one by one
if ($key != "author") { //does every property except author
$work[$key] = self::sentenceCase($work[$key], $key); //lowercases everything but the bracketed words
}
}
Command "/home/vagrant/venv/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tm
p/pip-build-yof3w9qh/m2crypto/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f
.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --r
ecord /tmp/pip-jbxkvphj-record/install-record.txt --single-version-externally-managed --co
mpile --install-headers /home/vagrant/venv/include/site/python3.6/m2crypto" failed with er
ror code 1 in /tmp/pip-build-yof3w9qh/m2crypto/
@rileymjohnson
rileymjohnson / gist:fc1d131c6d9f6b37231514e0464b1dc5
Created June 18, 2018 15:52
Error when running flask app with M@Crypto
flask.cli.NoAppException: While importing "stumpf.wsgi", an ImportError was raised:
Traceback (most recent call last):
File "/home/vagrant/venv/lib/python3.6/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
File "/vagrant/stumpf/wsgi.py", line 3, in <module>
from stumpf.app import create_app
File "/vagrant/stumpf/app.py", line 15, in <module>
from stumpf.views import (annotation_app_bp, artifact_bp, assignment_bp,
File "/vagrant/stumpf/views.py", line 12, in <module>