Skip to content

Instantly share code, notes, and snippets.

View Lokno's full-sized avatar

Lokno Lokno

View GitHub Profile
@Lokno
Lokno / cksum_function.c
Last active July 10, 2019 00:39
Posix checksum of all return values given every possible input to a single-parameter single-precision function
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef union
{
unsigned int ui;
unsigned char c[4];
float f;
@Lokno
Lokno / cuda_kernel_query.py
Last active April 3, 2019 21:32
Script that compiles a CUDA application to report the attributes of a kernel
# Compiles a CUDA application to report the attributes of a kernel
#
# usage: cuda_kernel_query.py <file> <entry name> [<define list>]
#
# file - name of the CUDA source file contain the kernel of interest
# entry name - name of the kernel to examine
# define list - comma delimited list of proprocessor defines for compilation
#
# If BLOCK_SIZE is defined in the file, this value is used in the occupancy
# calculation, otherwise the blockSize returned by
@Lokno
Lokno / run_handler.py
Created March 25, 2019 18:10
Python 3 script for running an application multiple times
# Script for running an application multiple times
#
# usage run_handler.py "<app + args>" <times> [output.csv]
#
# This script runs the a process multiple times and reports the
# average running time. Optionally, a file name can be provided,
# and the script will append the execution of each completed time
# into a file of that name.
#
# The script further estimates its total running time after the
@Lokno
Lokno / twitch_slack_bot.py
Created February 22, 2019 21:41
Simple slack bot that polls twitch and announces when users are active
import os,time
from slackclient import SlackClient
from twitch import TwitchClient
client = TwitchClient(client_id=os.environ.get('TWITCH_TOKEN'))
# Dictionary of twitch accounts
twitchAccounts = {'NAME' : {'username' : 'TWITCH_USERNAME'}}
wait_time = 60
@Lokno
Lokno / pairs.py
Last active November 21, 2021 23:14
Short python 3 script for randomly generating giftees for a gift exchange between 2 or more people.
from random import shuffle
from sys import argv
from pathlib import Path
names = []
if len(argv) == 2:
file_path = Path(argv[1])
if not file_path.exists():
print(f'File not found: {argv[1]:s}')
@Lokno
Lokno / generate_hanoi_problem.py
Created October 31, 2018 19:14
Python script to generate a PDDL format problem for the hanoi problem. For use with hanoi-domain.pddl.
num_disks = 15
num_pegs = 3
disks = ['disk%d' % (i+1) for i in range(num_disks)]
pegs = ['peg%d' % (i+1) for i in range(num_pegs)]
filename = 'hanoi-problem.pddl'
init = ['(clear disk1)']
goals = ['(clear disk1)']
@Lokno
Lokno / doormon.py
Last active August 18, 2018 05:30
A discord bot that reports changes to a pin on the RaspberryPi GPIO (used for detecting door knocks via a SW-420 Vibration Switch). Python 3.7.0
import discord
import asyncio
import RPi.GPIO as GPIO
import traceback
from discord.ext import commands
TOKEN = 'BOT_TOKEN_HERE'
description = '''A bot that reports changes to a pin on the GPIO'''
@Lokno
Lokno / screen_aligned_triangle.fx
Last active August 2, 2018 17:58
Renders a single screen-aligned triangle that fills the screen without a vertex buffer
// Renders a single screen-aligned triangle that fills the screen without a vertex buffer
// Creates texture coordinates with (0,0) in the top left and (1,1) in the bottom right
//
// DX11 API calls:
// m_pD3D11Device->IASetInputLayout(NULL);
// m_pD3D11Device->IASetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
// m_pD3D11Device->Draw(3, 0);
struct VSOut
{
# Python 3 script that reads the latest tweets that
# match the search term (line 21) and appends the url to
# the first video associated with each tweet to file
# See line 47 for the file name
# tested with Python 3.6.4
import tweepy
import signal
import sys
@Lokno
Lokno / stream_vids.html
Last active April 29, 2018 19:17
Basic javascript web page that streams a list of videos from a text file.
<!-- Streams a list of videos from a text file -->
<!-- Text file format: integer,url -->
<!-- Tested with Google Chrome Version 66.0.3359.139 (Official Build) (64-bit) -->
<!-- To run a simple local web server -->
<!-- type "python -m http.server 8000" at the command line -->
<!-- then direct your browser to localhost:8000 -->
<html>