Skip to content

Instantly share code, notes, and snippets.

View noudadrichem's full-sized avatar
💻
Learning the sh*t out of things

Noud noudadrichem

💻
Learning the sh*t out of things
View GitHub Profile
import Logger from "../lib/logger";
import axios from "axios";
import { createCanvas, loadImage, registerFont } from "canvas";
import path from "path";
import ColorThief from "colorthief";
import { uploadImage } from "../resolvers/imgResolver";
import { KeycapsetModel } from "../models";
registerFont(__dirname + "../../../static/Rubik-SemiBold.ttf", {
family: "Rubik Semi",
docker run -d -p 49160:22 -p 49162:8080 -p 49161 -v oracledb thebookpeople/oracle-xe-11g
@noudadrichem
noudadrichem / isColourDarkOrLight.ts
Created September 7, 2020 07:02
Gives back tags based on RGB code if it's light or dark
public isColourDarkOrLight(rgb: number[]): 'light' | 'dark' {
// RGB to HSP equation: http://alienryderflex.com/hsp.html
const [r, g, b] = rgb;
const hsp = Math.sqrt(
0.299 * (r * r) +
0.587 * (g * g) +
0.114 * (b * b)
);
return hsp > 127.5 ? 'light' : 'dark';
}
@noudadrichem
noudadrichem / toSlug.ts
Last active July 22, 2020 12:28
Escape invalid chars in string to create a slug
const toSlug = 'every thing you $ want. To b3 eScaped';
const slug = toSlug.toLowerCase()
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes
import * as fs from 'fs';
import * as ffmpeg from 'fluent-ffmpeg';
class VideoConvertService {
public connection: any;
public PATH: string = 'videos';
public async saveVideoToMachine(bannerSetId: string, videoBinaryString: any, extention: string, encoding: string = 'utf-8'): Promise<any> {
const filename = bannerSetId;
const path: string = `${this.PATH}/${filename}.${extention}`;
import React from 'react';
interface TableProps {
data: any[];
headings?: string[]
}
function Table(props: TableProps): JSX.Element {
const { data = [], headings } = props;
" Vim color file
" Converted from Textmate theme City Lights using Coloration v0.4.0 (http://github.com/sickill/coloration)
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
@noudadrichem
noudadrichem / ultra-unique-id.js
Created January 10, 2019 22:36
Returns a id string with a timestamp in it
const timestamp = (new Date().getTime() / 1000 | 0).toString(16);
const uniqueTimeStampId = (stamp) => stamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, () => (Math.random() * 16 | 0).toString(16)).toLowerCase()
Math.floor(Math.random() * 16777215).toString(16)
@noudadrichem
noudadrichem / getRandomString.js
Created October 4, 2019 10:23
Return a random string with custom length from assigned characters
function getRandomString(wishedIdLength) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=-[]\|';
var charactersLength = characters.length;
for (let i = 0; i < wishedIdLength; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}