Skip to content

Instantly share code, notes, and snippets.

View edalorzo's full-sized avatar

Edwin Dalorzo edalorzo

View GitHub Profile

Keybase proof

I hereby claim:

  • I am edalorzo on github.
  • I am edalorzopp (https://keybase.io/edalorzopp) on keybase.
  • I have a public key ASBbqjbS0EQZnXUoeusnFHNOpp8pXLXRmJkyjvMI0PFU9Ao

To claim this, I am signing this object:

@edalorzo
edalorzo / CmakeLists.txt
Created November 4, 2021 07:48
Configure PDCurses with CMake
cmake_minimum_required(VERSION 3.20)
project(MyProject)
set(CMAKE_CXX_STANDARD 20)
set(CURSES_LIBRARIES "libs")
include_directories("include")
link_directories("${CMAKE_SOURCE_DIR}/lib")
find_library(PDCURSES NAMES "pdcurses" HINTS "${CMAKE_SOURCE_DIR}/lib")
@edalorzo
edalorzo / basic-list-functions.sml
Last active July 15, 2021 17:04
Learning SML - Basic List Functions
(* Returns the head of a list. *)
fun head(xs) =
case xs of
[] => raise List.Empty
| (x::_) => x
(* Returns the tail of a list. *)
fun tail(xs) =
case xs of
[] => raise List.Empty
package com.dalorzo.nio;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.*;
public class SelectedSockets {
private static int PORT_NUMBER = 1234;
@edalorzo
edalorzo / Streams.sml
Last active April 19, 2020 19:17
Stream Implementation in SML
datatype 'a stream = Empty | Cons of 'a * (unit -> 'a stream)
fun from n = Cons(n, fn () => from(n +1))
fun takeWhile f xs =
case xs of
Empty => Empty
| Cons(h,t) => if not(f(h))
then Empty
else Cons(h, fn () => takeWhile f (t()))
@edalorzo
edalorzo / polynomials.sml
Created April 11, 2013 23:34
Polynomial sum and multiplication
(* Adds two polynomials. *)
fun padd([],Q) = Q
| padd(P,[]) = P
| padd((p:real)::P,q::Q) = (p+q) :: padd(P,Q)
(* Multiplies polynomial by scalar. *)
fun smult([],q:real) = []
| smult(p::P, q) = (p*q)::smult(P,q)
@edalorzo
edalorzo / befunge.js
Created December 12, 2013 22:25
Befunge-93 Interpreter
var interpret = (function(){
var stack = [];
var sysout = [];
var dir = '>'
var strmode = false;
var skipmode = false;
var pc = {row:0,col:0};
var program = [];
(function(){
var index = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/','='];
var octets = ["","0","00","000","0000","00000","000000","0000000"];
var sixths = ["","00000","0000","000","00","0"];
var paddings = [[],[],[64,64],[],[64]];
unction Value(value){
this.value = value || 0;
}
Value.prototype.eval = function(){ return this; };
Value.prototype.valueOf = function(){ return this.value.valueOf(); };
Value.prototype.toString = function(){ return this.value.toString(); };
var createOperator = function(){
function reduce(oper){
asDecimal = function(){
var romans = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000 };
return function(roman){
return roman.split('').map(function(r){ return romans[r];})
.reduce(function(res,n,i,digits){
var prev = i > 0 ? digits[i-1] : 0;
return prev < n ? res + n - 2 * prev : res + n;
},0);
};
}();