Skip to content

Instantly share code, notes, and snippets.

View jcavat's full-sized avatar

Joel Cavat jcavat

  • Switzerland, Geneva
View GitHub Profile
{-|
- Description: Haskell version
- provide the `paginate` function helping to provide a group of buttons
- indicating the current page on a list. Maximum 10 buttons are showed.
- if the number of pages is higher than 10, we change some buttons by
- '...'.
-
- Copyright: jcavat, 2017
- License: WTFPL
- Stability: experimental
@jcavat
jcavat / docker-compose.yml
Last active June 11, 2019 14:10
docker-compose config file with mysql and phpmyadmin
version: "2"
services:
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
@jcavat
jcavat / Dockerfile
Last active June 18, 2024 13:20
docker-compose with php/mysql/phpmyadmin/apache
FROM php:7.1.2-apache
RUN docker-php-ext-install mysqli
@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 / 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 / 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 / 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 / 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;
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char* id;
int capacity;
} Room;
typedef struct {
char* fullname;
@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;