Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / Running.txt
Created July 23, 2018 08:08
C++ Scala JNI - Java Native Interface - Example - Calling C++ from Scala / Java
Compile the C++ code creating a shared library (or shared object in UNIX)
$ clang++ TestJNI.cpp -o libTestJNI.so -fPIC -shared -std=c++11 -I$HOME/opt/java/include -I$HOME/opt/java/include/linux
Run the application
$ scala -save load.scala
dir = /home/archbox/opengl/jni/libTestJNI.so
Hello world java
i = 0
@caiorss
caiorss / higherOrderFunction.m
Created July 18, 2018 14:48
Matlab / Octave Higher Order Functions - quasi-Functional Programming
% Author: Caio Rodrigues
% Objective: Test higher order functions and anonymous functions.
%
% Limitations: Doesn't support assignment in lambda function and also doens't support multiple lines.
% Other limitations are that functions cannot be stored in data structures or returned from functions.
%
octave:30> computeTable = @(xmin, dx, xmax, fn) [ (xmin:dx:xmax)' (fn(xmin:dx:xmax))']
computeTable =
octave:15> computeTable(0.0, 0.1, 2.0, @(x)[2 * x + 1.0])
@caiorss
caiorss / output.txt
Last active July 17, 2018 14:07
Octave/Matlab script for solving parabolic PDE partial derivate equation, specifically heat equation.
$ octave --no-gui heatEquation2.m
Nx = 10
Nt = 5
dx = 0.10000
dt = 0.0050000
c = 1
xmin = 0
xmax = 1
tmin = 0
tmax = 1
@caiorss
caiorss / blasLapack1.cpp
Created July 6, 2018 20:29
Callign Lapack and Blas fortran libraries from C++11
#include <iostream>
#include <iomanip>
#include <vector>
#include <chrono>
// External linkage without header file goes here.
// The symbols here are defined in *.o (Object files)
// or shared libraries. (*.so - UNIX) or (*.dll - Windows)
extern "C" {
// WARNING: This is the GFortran ABI which encodes symbols with underscore (_)
@caiorss
caiorss / bindTest-ouput.sh
Created July 6, 2018 17:12
C++11 std::bind usage examples with higher order functions std::functions and function-objects C++'s functor
$ clang++ bindTest.cpp -std=c++11 -Wall -Wextra -g -o out.bin && ./out.bin
======== Test 1 ========
bindTest.cpp:58: ; sum10(2.0) = 12
bindTest.cpp:59: ; sum10(4.5) = 14.5
bindTest.cpp:60: ; sum10(25.0) = 35
======== Test 2 ========
bindTest.cpp:66: ; vectorLenAsFunctionOfX(4.0) = 27.2213
bindTest.cpp:67: ; std::bind(vectorLength, _1, 10.0, 25.0)(4.0) = 27.2213
bindTest.cpp:68: ; vectorLenAsFunctionOfX(10.0) = 28.7228
@caiorss
caiorss / ConstrainedTypesExamples.fsx
Created June 9, 2017 21:54 — forked from swlaschin/ConstrainedTypesExamples.fsx
Examples of creating constrained types in F#
module ConstrainedTypes =
open System
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//
@caiorss
caiorss / Demonstrations.ml
Last active June 7, 2018 08:53 — forked from rizo/pipes.ml
Quick self-contained demonstration of coroutine pipes in OCaml. - Talk given by Rizo Isrof
(**
Talk given by Rizo Isrof
- https://pusher.com/sessions/meetup/the-realtime-guild/realtime-stream-processing-with-coroutines
- https://www.reddit.com/r/ocaml/comments/66pe0s/stream_processing_with_coroutines_from_c_to_ocaml/
*)
# empty ;;
- : ('a, 'b, unit) pipe = Ready ()
#
@caiorss
caiorss / Free.fsx
Created March 15, 2017 18:21
Free monad interpreter in F# (based on: http://programmers.stackexchange.com/a/242803/145941)
type DSL<'next> =
| Get of string * (string -> 'next)
| Set of string * string * 'next
| End
with static member fmap f = function
| Get (k, c) -> Get (k, f << c)
| Set (k, v, c) -> Set (k, v, f c)
| End -> End
type FreeDSL<'a> =
@caiorss
caiorss / lorenz.py
Created March 10, 2017 18:09 — forked from NT7S/lorenz.py
Draw the Lorenz system in Python/GTK
# lorenz.py
# 5 March 2016
#
# Copyright 2016 Jason Milldrum
#
# Draw the Lorenz system in a GTK window
# See https://en.wikipedia.org/wiki/Lorenz_system
import math
import gi
@caiorss
caiorss / Monaso.cs
Created March 10, 2017 17:45 — forked from HiroNakamura/Monaso.cs
Ejemplos en C#
/*
Ejemplos de código en C#
*/
//32 for
using System;
public class Monaso{