Skip to content

Instantly share code, notes, and snippets.

View jcavat's full-sized avatar

Joel Cavat jcavat

  • Switzerland, Geneva
View GitHub Profile
@jcavat
jcavat / demo.i
Created January 13, 2021 11:06
Python Wrapper for C++ with SWIG
%module demo
%{
#include "test.hpp"
%}
%include "test.hpp"
@jcavat
jcavat / Status.java
Created October 9, 2020 09:39
Polymorphic nested classes
import java.time.LocalDate;
import java.util.function.Consumer;
public interface Status {
static class Running implements Status {
private Running() {
}
public boolean isRunning() {
@jcavat
jcavat / ResourceApp.java
Created July 16, 2020 12:24
used for personal blog
import java.util.List;
interface Resource {
String info();
}
class Room implements Resource {
private String id;
private int capacity;
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char* id;
int capacity;
} Room;
typedef struct {
char* fullname;
@jcavat
jcavat / test.rs
Created October 12, 2019 09:14
ast with pattern match through visitor pattern in Rust for polymorphic return type
struct Cons {
value: i32,
}
struct AddExpr<T> {
lhs: Box<dyn Accept<T>>,
rhs: Box<dyn Accept<T>>
}
trait Accept<T> {
fn accept(&self, v: &dyn Visitor<Result = T>) -> T;
@jcavat
jcavat / trait_pattern_match.rs
Created October 11, 2019 18:15
Pattern match on traits in Rust
struct Foo{ value: u32 }
struct Bar{ value: u32 }
trait Base<T> {
fn accept(&self, v: &dyn Visitor<Result = T>) -> T ;
}
impl <T>Base<T> for Foo {
fn accept(&self, v: &dyn Visitor<Result = T>) -> T {
v.visit_foo(&self)
}
@jcavat
jcavat / typeclass_multiple_args.scala
Last active October 10, 2019 11:11
Type class method with multiple args
trait Testable[T,R] {
def test(t: T, s: String): R
}
object Testable {
def apply[T,R](implicit testable: Testable[T,R]): Testable[T,R] = testable
implicit class Ops[T,R](t: T)(implicit testable: Testable[T,R]) {
def test(s: String): R = Testable[T,R].test(t, s)
}
implicit val stringCan: Testable[String,String] = (s1,s2) => s1 + s2
}
@jcavat
jcavat / App.java
Created April 9, 2019 08:23
Try with resources with jdbc
import java.sql.*;
public class App {
// JDBC driver name and database URL
static final String driver = "com.mysql.cj.jdbc.Driver";
static final String dbUrl = "jdbc:mysql://ip_address:3306/databasename";
// Database credentials
static final String user = "user";
static final String pass = "pass";
@jcavat
jcavat / .htaccess
Last active June 11, 2019 14:12
Docker Abaplans
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
@jcavat
jcavat / Dockerfile
Last active February 25, 2024 13:58
docker-compose with php/mysql/phpmyadmin/apache
FROM php:7.1.2-apache
RUN docker-php-ext-install mysqli