Skip to content

Instantly share code, notes, and snippets.

@programaths
programaths / text-adventure.kt
Created May 31, 2017 19:39
An example of text adventure in Kotlin
/*
* This file implement a very simple text game engine and a DSL.
*/
fun main(args: Array<String>) {
val game=Branch("You awake in a dark forest. Where do you want to go ?"){
WalkNorth() leadsTo TerminalBranch("You went too far in the dark and have been killed by a somber creature")
WalkSouth() leadsTo TerminalBranch("You just fel from a cliff. Dumb move !")
WalkEast() leadsTo Branch("""In front of you is a yellowish box.
It really stand out from the night."""){
OpenAction() leadsTo TerminalBranch("A snake pop out of the box and bite you. You die of a painful poisoning!")
@programaths
programaths / Wims-Mat-Puzzle.kt
Created August 14, 2017 17:04
Solving the Wims Mat Puzzle
package com.wimpuzzle
import java.util.*
fun main(args: Array<String>) {
val solver = Solver()
solver.solve()
}
class Piece(val positions: Array<Array<Array<Int>>>,val id:Int,var orientation: Int=0){
@programaths
programaths / rotateArrayLinearAlgebra.php
Created September 22, 2017 07:27
rotate Array Linear Algebra
<?php
function matMul($a,$b){
$countI = count($a);
$countJ = count($b[0]);
$countK = count($b);
$c=[];
for($i=0;$i<$countI;$i++){
for($j=0;$j<$countJ;$j++){
$sum = 0;
@programaths
programaths / array-rotate-rl.php
Created September 22, 2017 17:13
Rotate an array left and right
<?php
function matMul( $a, $b ) {
$countI = count( $a );
$countJ = count( $b[0] );
$countK = count( $b );
$c = [];
for ( $i = 0; $i < $countI; $i ++ ) {
for ( $j = 0; $j < $countJ; $j ++ ) {
$sum = 0;
for ( $k = 0; $k < $countK; $k ++ ) {
@programaths
programaths / testing-system-classes.js
Created November 19, 2018 10:20
Mocha test for REALM showing that if a class name is "ROLE" or "USER", it overrides "__ROLE" and "__USER" detection and leads duplicate or missing classes
const Realm = require('realm');
const LOGIN_URL = `http://localhost:9080/`;
const SYS_UNAME = '';
const SYS_PWD = '';
async function loginSysUser29(){
return Realm.Sync.User.login(LOGIN_URL,Realm.Sync.Credentials.usernamePassword(SYS_UNAME,SYS_PWD));
}
@programaths
programaths / fixing-roles-users.js
Last active November 19, 2018 14:13
fixing roles & Users
/**
*
* @param {Array<{name:string}>} schema
*/
function fixSchema(schema) {
let fixedSchema = [];
let hasUser = false;
let hasSysRole = false;
let hasRole = false;
@programaths
programaths / auth.js
Created November 27, 2018 07:52
Working case of connection
const fetch = require('node-fetch');
const {ApolloClient,gql} = require('apollo-boost');
const {createHttpLink} =require('apollo-link-http');
const {WebSocketLink} =require('apollo-link-ws');
const WebSocket = require('ws');
const {InMemoryCache} = require('apollo-cache-inmemory');
const TEST_EMAIL = 'test-email';
const TEST_PWD = 'test-password';
@programaths
programaths / overlapping-rectangles.frag
Created September 7, 2019 19:02
Very simple shader showing how to compose a figure and have layers
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 rotate(vec2 v, float a) {
float s = sin(a);
@programaths
programaths / firstNonRepeating.go
Created August 2, 2021 15:43
firstNonRepeating
package main
import "container/heap"
// Mind that this is slower than doing one pass to count occurances of each letter then a second pass to get the first non repeating letter
// This one does something else though, it will take the first least repeated letter. So, with any permutation of "aaaabbbcc" it would yield "c"
type indexedChar struct {
index int
rune rune
@programaths
programaths / matrix.py
Created October 8, 2022 12:12
Code pour générer une vidéo sur la multiplication de matrices
from manim import *
class CreateCircle(Scene):
def construct(self):
mat1_data = [[1, 3, 5], [7, 9, 11], [13, 15, 17]]
mat1 = Matrix(mat1_data, left_bracket="(",
right_bracket=")")
mat2_data = [[2, 4, 6], [8, 10, 12], [14, 16, 18]]
mat2 = Matrix(mat2_data, left_bracket="(",