View inline.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import sys | |
import os | |
import errno | |
FUNC = ctypes.CFUNCTYPE(None) | |
PROT_NONE = 0 | |
PROT_READ = 1 | |
PROT_WRITE = 2 |
View 452874.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
By only adding + - * into the string 452874 (in that order), | |
how many way can you get to -18? | |
""" | |
N = "452874" | |
M = -18 | |
OPERATIONS = [None, '+', '-', '*'] |
View draft.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let input = read_input_from_file("day01/input.txt").unwrap(); | |
// Part 1 | |
let mut count = 0; | |
let mut last = -1; | |
for &n in &input { | |
if n > last { | |
count += 1; | |
} |
View alarmtimer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# POSIX Alarm Timer example using Python ctypes | |
# | |
# Author: David Coles <coles.david@gmail.com> | |
# Date: 2012-03-19 | |
# | |
# To the extent possible under law, the author(s) have dedicated all copyright | |
# and related and neighboring rights to this software to the public domain | |
# worldwide. This software is distributed without any warranty. |
View fifo_size.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the number of bytes unread in a fifo. | |
# David Coles <coles.david@gmail.com> | |
import argparse | |
import ctypes | |
import fcntl | |
import os | |
import sys | |
import termios |
View fsm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt::Debug; | |
pub trait State: Debug { | |
fn execute(&self) -> Transition; | |
} | |
pub trait TransitionTo<S: State + 'static>: State { | |
fn transition_to(&self, to: &'static S) -> Transition { | |
Transition { to } | |
} |
View tokio-server.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tokio-based server | |
use std::io; | |
use std::iter::FromIterator; | |
use std::time::Duration; | |
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |
use tokio::net::{TcpListener, TcpStream}; | |
// Listening server. |
View windows-nfs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of NFC using Windows Proximity APIs | |
// Tested using Sony RC-S380 (make sure you enable NFP in the driver). | |
use winrt::*; // import various helper types | |
use winrt::windows::foundation; | |
use winrt::windows::networking::proximity; | |
use std::{thread, time}; | |
const URL: &str = "https://dcoles.net"; |
View xinput.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple Wrapper around XInput API | |
# | |
# Author: David Coles <coles.david@gmail.com> | |
import ctypes | |
from ctypes.wintypes import BYTE, WORD, SHORT, DWORD | |
class XInputGamepad(ctypes.Structure): | |
_fields_ = [ |
View appimage.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run AppImage container | |
set -e | |
function _mount { | |
local target | |
target="$(mktemp --tmpdir --directory appimage.XXXXXXXXXX)" | |
/bin/mount --types squashfs -o offset="${2:-0}" --read-only -- "${1}" "${target}" | |
echo "${target}" | |
} |
NewerOlder