This file contains hidden or 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
#![feature(never_type)] | |
use std::ffi::{CString, CStr, OsStr}; | |
use std::ptr; | |
extern crate libc; | |
use libc::{c_void, c_char, c_int,}; | |
#[repr(C)] pub struct Handle { _private: () } |
This file contains hidden or 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 | |
set -e | |
# Update sources to nz mirrors | |
sudo sed -i"" 's|http://deb.debian.org|http://ftp.nz.debian.org|g' /etc/apt/sources.list.d/base.list | |
# Install backports | |
BACKPORT_FILE=/etc/apt/sources.list.d/debian-backports.list | |
if [ ! -f $BACKPORT_FILE ]; then |
This file contains hidden or 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
extern crate embedded_hal; | |
use embedded_hal::blocking::spi::{Write, Transfer}; | |
extern crate embedded_hal_mock; | |
use embedded_hal_mock::MockError; | |
use embedded_hal_mock::spi::{Mock as SpiMock, Transaction as SpiTransaction}; | |
enum Operation<'a> { | |
Write(&'a [u8]), |
This file contains hidden or 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
// build.rs example for rust libraries to generate c headers | |
// https://gist.github.com/ryankurte/8d3abcb0249269d56e07b183aa06ba62 | |
// Copyright 2018 Ryan Kurte | |
// Usage | |
// 1. Add rusty-binder and rusty-cheddar as build dependencies to your top level Cargo.toml | |
// [build-dependencies] | |
// rusty-binder = { git = "https://gitlab.com/rusty-binder/rusty-binder.git" } | |
// rusty-cheddar = { git = "https://gitlab.com/rusty-binder/rusty-cheddar.git" } | |
// 2. Set your crate type to static in Cargo.toml |
This file contains hidden or 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
#define QUEUE_SIZE 16 | |
int main(int argc, char** argv) { | |
queue_t example = {0, 0, QUEUE_SIZE, malloc(sizeof(void*) * QUEUE_SIZE)}; | |
// Write until queue is full | |
for (int i=0; i<QUEUE_SIZE; i++) { | |
int res = queue_write(&example, (void*)(i+1)); | |
assert((i == QUEUE_SIZE - 1) ? res == -1: res == 0); | |
} |
This file contains hidden or 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
// A HardFault handler to make life easier when debugging | |
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/Cihcfefj.html | |
// The smol version | |
void HardFault_Handler(void) { | |
SCB_Type* scb = SCB; | |
(void*)scb; | |
__asm("BKPT #0"); | |
while(1); | |
} |
This file contains hidden or 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
#include <stdint.h> | |
#include <stdbool.h> | |
uint16_t crc16_ccit_FFFF(uint32_t len, uint8_t* data) { | |
uint16_t crc = 0xFFFF; | |
for (uint32_t i=0; i<len; i++) { | |
uint16_t d = data[i]; | |
d ^= crc >> 8; |
This file contains hidden or 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
#include <avr/io.h> | |
#include <util/delay.h> | |
// Board Definitions | |
#define LED0_PIN 0 | |
#define LED1_PIN 3 | |
#define SW_PIN 2 | |
// IO Helpers | |
#define IO_PORT PORTB |
This file contains hidden or 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 SQLi Example | |
// See: | |
// https://www.w3schools.com/sql/sql_injection.asp | |
// https://www.owasp.org/index.php/Testing_for_SQL_Injection_(OTG-INPVAL-005) | |
var express = require('express') | |
var sqlite3 = require('sqlite3').verbose(); | |
var db = new sqlite3.Database('./test.db'); | |
var app = express() |
This file contains hidden or 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
// Demo 1 | |
// clang -fno-stack-protector -fno-sanitize=safe-stack -D_FORTIFY_SOURCE=0 -m32 -Wl,-no_pie -O0 -g demo2.c -o demo2.o | |
#include <stdio.h> | |
#include <string.h> | |
char password[] = "password"; | |
int get_password() { | |
int auth_ok = 0; |