Skip to content

Instantly share code, notes, and snippets.

@dagon666
dagon666 / io_measure.cpp
Created December 4, 2014 21:36
io_measure
#include <string>
#include <iostream>
#include <chrono>
void synced(const std::string& s, unsigned int n = 0) {
std::cout.sync_with_stdio(true);
while (n--) std::cout << s << std::endl;
}
#include <iostream>
#include <type_traits>
template <typename ... > struct my_tuple {};
template <typename T, typename ... Ts>
struct my_tuple<T, Ts...> : my_tuple<Ts...> {
typedef T type;
type value;
my_tuple(T t, Ts ... ts) : value(t), my_tuple<Ts...>(ts...)
@dagon666
dagon666 / Makefile
Created October 19, 2014 20:10
NegaMax example - Tic Tac Toe
EXE=ttt
CC=gcc
all: $(EXE)
%.o: %.c
$(CC) -std=c99 -g -c -o $@ $< -I.
$(EXE): nega_tests.o
$(CC) -o $(EXE) $< -lm -g
@dagon666
dagon666 / main.c
Created July 20, 2014 21:20
arduino uscope experiment
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include "pca.h"
@dagon666
dagon666 / gist:1b80851a0ff1ad10d0c6
Created May 11, 2014 18:16
simple plasma effect
for (uint16_t i = 0; i < 256; i++) {
sin_table[i] = (cos(i/2)*sin(i))*31 + 32;
}
while(1) {
pcd8544_gotoxy(&lcd, 0, 0);
for (uint8_t x = 0; x<PCD8544_W; x++) {
for (uint8_t y = 0; y<PCD8544_H; ) {
uint8_t buffer[(PCD8544_W * PCD8544_H) >> 3] = {0x00};
for (uint8_t x = 0; x < PCD8544_W; x++) {
for (uint8_t y = 0; y < PCD8544_H; y++) {
if (common_ditherPoint(((float)y/PCD8544_H)*64, x, y))
PCD8544_SET_BIT_HIGH(buffer, x, y);
}
}
pcd8544_blit(&lcd, buffer);
uint8_t buffer[(PCD8544_W * PCD8544_H) >> 3] = {0x00};
for (uint8_t x = 0; x < PCD8544_W; x++) {
for (uint8_t y = 0; y < PCD8544_H; y++) {
if (!(x&y)) PCD8544_SET_BIT_HIGH(buffer, x, y);
}
}
pcd8544_blit(&lcd, buffer);
@dagon666
dagon666 / main.c
Created May 11, 2014 15:34
pcd8544 program template
#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <util/delay.h>
#include <math.h>
#include "main.h"
#include "pca.h"
@dagon666
dagon666 / cli.c
Last active January 1, 2016 20:49
cli offline
#include "cli.h"
#include <string.h>
#include <stdio.h>
#define POSINC(__x) (((__x) < (CLI_CMD_BUFFER_SIZE - 1)) ? (__x + 1) : (__x))
#define POSDEC(__x) ((__x) ? ((__x) - 1) : 0)
/* ================================================================================ */
@dagon666
dagon666 / argc.c
Created December 31, 2013 16:24
count arguments
static unsigned char _cli_count_arguments(t_cli_ctx *a_ctx) {
char *cur = a_ctx->cmd;
unsigned char cnt = 0;
for(;;) {
while (*cur == ' ') cur++;
if (*cur == '\0') break;
cnt++;
while (*cur != '\0' && *cur != ' ') {
cur++;
}