Skip to content

Instantly share code, notes, and snippets.

View sakex's full-sized avatar
🇮🇱

Alexandre Senges sakex

🇮🇱
View GitHub Profile
// src/bindings.rs
#[link(name = "gui", kind = "static")]
extern "C" {
pub fn register_button(engine: *mut c_void, button: *mut c_void);
}
// src/engine.rs
use std::ffi::c_void;
use std::os::raw::c_char;
use crate::bindings::{engine_factory, register_button, AbstractButtonBinding};
use crate::Button;
pub struct Engine {
ptr: *mut c_void
}
// src/main.rs
mod button;
mod engine;
mod bindings;
use button::Button;
pub struct CounterButton {
count: i32
}
pub trait Button {
fn click(&mut self);
fn inner_text(&mut self) -> String;
}
pub struct CounterButton {
count: i32
}
impl Button for CounterButton {
// main.cpp
#include <GUI/engine.hpp>
#include "CounterButton.hpp"
int main() {
// Instantiate the hypothetical engine
Engine engine();
// Instantiate the button
auto * counter = new CounterButton();
// Adds button to the view
engine.addButton(counter);
// CounterButton.hpp
#ifndef MEDIUM_COUNTERBUTTON_HPP
#define MEDIUM_COUNTERBUTTON_HPP
#include <GUI/AbstractButton.hpp>
class CounterButton: public AbstractButton {
public:
CounterButton(): count(0) {
}
// AbstractButton.hpp (in GUI library)
#ifndef MEDIUM_ABSTRACT_BUTTON_H
#define MEDIUM_ABSTRACT_BUTTON_H
#include <string>
class AbstractButton {
virtual void click() = 0;
virtual std::string innerText() = 0;
struct Point {
x: f64,
y: f64,
z: f64,
}
impl Point {
pub fn mid_point(&self, other: &Point) -> Point {
Point {
x: (self.x + other.x) / 2.0,
@sakex
sakex / sim.py
Last active May 2, 2020 13:47
Agents simulation COVID
import numpy as np
from numpy.random import uniform, randint
from typing import Tuple, List, Set
class Agent:
def __init__(self, x: float, y: float, contamined: bool):
self.__x: float = x
self.__y: float = y
self.__contamined: bool = False
self.__days_contamined: int = 0
function forEach(arr, func) {
const len = arr.length;
for(let i = 0; i < len; ++i) func(arr[i])
}
const l = [1,2,3,4,5];
function logTimes2(x) {
console.log(x*2);
}