Skip to content

Instantly share code, notes, and snippets.

View tautologico's full-sized avatar

Andrei Formiga tautologico

  • UFPB
  • João Pessoa, Paraíba
View GitHub Profile
@tautologico
tautologico / buildcrossgcc.sh
Last active March 18, 2024 11:43
Build gcc cross-compiler for armv7-a (Cortex-A)
#!/bin/sh
# Download binutils, gcc, the linux kernel, glibc
# define the prefix
export PREFIX=/opt/armhf
# change PATH to include the target directory
export PATH=$PREFIX/bin:$PATH
@tautologico
tautologico / drivertest.cpp
Created June 6, 2012 02:58
Vector addition example using CUDA driver API
/*
* drivertest.cpp
* Vector addition (host code)
*
* Andrei de A. Formiga, 2012-06-04
*/
#include <stdio.h>
#include <stdlib.h>
#lang racket
;; Write a simple C64 assembly program to a PRG file, along with a line
;; of BASIC program to load the machine-language code.
;; The assembly program that will be run
(define program
(bytes #xA9 #x00 ; LDA #00
#x8D #x20 #xD0 ; STA $D020
#x8D #x21 #xD0 ; STA $D021
@tautologico
tautologico / adt.ts
Created October 17, 2022 00:23
Representing discriminated unions/ADTs in TypeScript
// Discriminated Union in TypeScript
interface Integer {
tag: 'integer';
value: number;
}
interface Sum {
tag: 'sum';
op1: Expression;
@tautologico
tautologico / chrpeekiter.rs
Created May 28, 2022 16:33
Peekable Char Iterator
use std::iter::Peekable;
use std::str::Chars;
fn main() {
let s = "Aussonderungsaxiom".to_string();
let mut bf = Buffer::new(&s);
println!("First character should be A: {}", bf.peek().expect("q"));
println!("First char: {}", bf.next().expect("q"));
println!("Next char: {}", bf.next().expect("q"));
@tautologico
tautologico / Activity.res
Created December 6, 2021 23:30
Call a web API using promises and log the result
// Fetch an activity from the Bored API
type promise<+'a> = Js.Promise.t<'a>
@send external then: (promise<'a>, @uncurry ('a => promise<'b>)) => promise<'b> = "then"
@send external thenResolve: (promise<'a>, @uncurry ('a => 'b)) => promise<'b> = "then"
module Response = {
type t<'data>
@send external json: t<'data> => promise<'data> = "json"
@tautologico
tautologico / Nodesrv1.res
Last active December 5, 2021 19:07
A simple Node server in ReScript
// example ported from
// "Web Development with Node and Express", 2nd edition
// by Ethan Brown
// bindings to the node API
type res
type req
type server
@module("http") external createServer : ( @uncurry (req, res) => unit ) => server = "createServer"
@tautologico
tautologico / contloop.scm
Last active June 26, 2020 08:28
TSPL 3rd ed., exercise 3.3.1
;; Use call/cc to write a program that loops indefinitely,
;; printing a sequence of numbers beginning at zero.
;; Do not use any recursive procedures, and do not use any assignments.
(let ((kontp (call-with-current-continuation (lambda (k) (cons k 0)))))
(let ((i (cdr kontp))
(kont (car kontp)))
(display i)
(display " ")
(kont (cons kont (+ 1 i)))))
@tautologico
tautologico / remacc.js
Created November 21, 2019 04:45
Remove acute accents in a string, if they're represented as separate characters
// removes acute accents represented in separate characters
// e.g. a + ' = á
function removeAcute(s) {
let res = ""
let i = 0
for (i = 0; i < s.length; ++i) {
if (s.codePointAt(i) != 769)
res = res + s.charAt(i)
}
return res
let py = document.querySelector('#playerFrame').
contentDocument.querySelectorAll('rt')
let escondePinYin = () => py.forEach( e => e.style.color = '#FFFFFF' )
let mostraPinYin = () => py.forEach( e => e.style.color = '#000000' )