Skip to content

Instantly share code, notes, and snippets.

@safiire
safiire / main.cpp
Created April 30, 2015 09:43
Example of returning a string initialized in the constructor
// Comple with g++ *.cpp -o prog //
#include <iostream>
#include "test.h"
using namespace std;
int main(int argc, char **argv){
Test test;
@safiire
safiire / memory_mapped_io.cpp
Created June 9, 2015 21:01
Manipulation of Memory Mapped Registers using C++ Templates (Technique from Olivier Gillet's Avril AVR Library)
#include <stdio.h>
#include <stdint.h>
//// Create some pretend Memory Mapped Registers
volatile uint64_t memory_mapped_registers[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
#define bit_depth uint64_t
#define mmio_byte(mem_addr) (*(volatile bit_depth *)(mem_addr))
@safiire
safiire / rc_filter.py
Last active January 17, 2019 06:06
Rewrote RC filter in Python as a refresher
#/usr/bin/env python
from sys import stdout
from math import pi, log10, pow
Tau = 2 * pi
TableWidth = 20
## Calculate Decibels
def db(ref, val):
@safiire
safiire / curiously_recurring_template_pattern.cpp
Created June 11, 2015 05:34
Curiously Recurring Template Pattern
////
// Curiously Recurring Template Pattern
#include <stdio.h>
template <typename T>
struct Counter {
// Static class members variables
static int objects_created;
static int objects_alive;
@safiire
safiire / template_magicks.cpp
Last active May 24, 2016 19:33
Using template meta-programming as a functional language in C++11
#include <iostream>
using namespace std;
////
// Pattern match on a list of types, recursively ask for the last one
template <typename Head, typename... Tail>
struct last {
using type = typename last<Tail...>::type;
};
@safiire
safiire / .csirc
Created September 3, 2015 05:30
A working .csirc file for Scheme readline
(use readline)
(current-input-port (make-readline-port))
(install-history-file #f ".csi.history")
(parse-and-bind "set editing-mode vi")
@safiire
safiire / rc_filter_simulation.scm
Last active September 4, 2015 02:51
RC Filter Circuit simulation in Scheme
;;;; RC Filter Simulation
;; Calculates the frequency response of an RC filter
;; and displays it with ASCII art
;; This is just a program I always write to learn a new programming language
;; I tried out Scheme's lazy lists for this
;;
;; Frequency Response
;; ----------------------------------------------------------------
;; |****************************** |
;; | ***** |
@safiire
safiire / pokémon_decrypt.c
Last active May 21, 2023 09:27
This is a C program to decrypt pokémon files
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define NICKNAMED(x) ((x & 0x80000000) >> 31)
#define IS_EGG(x) ((x & 0x40000000) >> 30)
#define SP_DEF_IV(x) ((x & 0x3e000000) >> 25)
#define SP_ATT_IV(x) ((x & 0x01f00000) >> 20)
@safiire
safiire / variadic_print.cpp
Created May 16, 2016 07:59
Interesting way of using the new variadic templates to create a variadic print() function.
// Compile with: g++ -std=c++11 variadic_print.cpp -o variadic_print
#include <iostream>
// No argument case
void print() {}
// Recursive Variadic Template
template <typename HEAD, typename ... TAIL>
void print(const HEAD& head, const TAIL& ... tail) {
@safiire
safiire / difference_equation.rb
Last active September 19, 2016 21:42
Modeling a filter's difference equation, so that it can invert itself.
#!/usr/bin/env ruby
# Really inefficient toy
####
## A little wrapper to make signals either with
## lambda functions or arrays.
class SignalFunction
def self.ramp
SignalFunction.new(lambda{|n| n < 0 ? 0r : n/1r})
end