Skip to content

Instantly share code, notes, and snippets.

View apotox's full-sized avatar
📚
reading

Safi eddine apotox

📚
reading
  • Senior Software Engineer
  • berlin
  • 13:23 (UTC +01:00)
View GitHub Profile
@apotox
apotox / types.ts
Created January 26, 2022 10:47
typescript: make some properties required from an optional props
type SomeRequired<T , TRequired extends keyof T> = T & Required<Pick<T,TRequired>>
//example
type TmpUser = {
photo?: string,
username?: string
}
type User = SomeRequired<TmpUser, 'username'>
@apotox
apotox / game.ts
Created January 9, 2022 17:00
rock-paper-scissors game ts
import canvas, { CANVAS_H, CANVAS_W } from "./canvas";
import Engine from "./engine";
import Button from "./entities/button";
import TouchSystem from "./systems/touch-system";
import { Images } from "./types";
import Client from "./socket-client";
import Counter from "./entities/counter";
import CounterSystem from "./systems/counter-system";
const BASE_URL = window.location.protocol + '//' + window.location.host;
const handler=()=>{
console.log("hello")
}
// call the handler function every 2sec
let stopper = setInterval(handler, 2000)
// stop the setInterval method
clearInterval(stopper)
@apotox
apotox / setInterval.go
Last active August 8, 2023 02:02
GoLang ⏱ setInterval alternative
package main
import (
"fmt"
"reflect"
"time"
)
// setInterval call p function every "interval" time
func setInterval(p interface{}, interval time.Duration) chan<- bool {
@apotox
apotox / Dockerfile
Created February 16, 2021 12:23
deploy your react js app using Dockerfile without nginx server
FROM node:12.0-slim
COPY . .
RUN yarn install
RUN yarn build
RUN npm install -g serve
EXPOSE 8080
CMD ["serve","-p","8080","build/"]
@apotox
apotox / fonts.conf
Last active September 23, 2020 09:20
custom fonts in aws lambda function
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>./MyFontDirectory/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
@apotox
apotox / serverless.yaml
Created September 23, 2020 09:13
ImageWatermark yaml definition
ImageWatermark:
handler: ImageWatermark
events:
- s3:
existing: true
bucket: ${self:custom.configs.UPLOAD_BUCKET}
event: s3:ObjectCreated:*
rules:
- suffix: .jpg
- s3:
@apotox
apotox / ImageWatermark.js
Created September 23, 2020 09:09
insert a watermark to any jpeg image pushed to an S3 bucket
// dependencies
const AWS = require("aws-sdk");
const util = require("util");
const sharp = require("sharp");
// get reference to S3 client
const s3 = new AWS.S3();
exports.compressImage = async (event, context) => {
// Read options from the event parameter.
@apotox
apotox / analogRead_and_the_interrupt_pins.ino
Last active July 6, 2020 17:28
AnalogRead and the interrupt pins
/*
-------------------
read more about this gist here: https://medium.com/@saphidev/analogread-and-the-interrupt-pins-f9c986d3fc0e
-------------------
*/
#define LED 13 //optionel
#define BTN A5 //ADC5
#define INTRPT 2 //PD2 refer to the INT0 vector
@apotox
apotox / attachInterrupt.ino
Created June 27, 2020 18:43
attachInterrupt example for the atmega328
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}