Skip to content

Instantly share code, notes, and snippets.

View ilkou's full-sized avatar
🍃
stuck between over-engineering and cargo-culting

Oussama ilkou

🍃
stuck between over-engineering and cargo-culting
View GitHub Profile
@ilkou
ilkou / shadcn-ui react-select.jsx
Created March 26, 2024 13:54
react-select with shadcn/ui
/* ----------- simple-select.js ----------- */
import * as React from 'react';
import Select from 'react-select';
import type { Props } from 'react-select';
import { defaultClassNames, defaultStyles } from './helper';
import {
ClearIndicator,
DropdownIndicator,
MultiValueRemove,
Option
@ilkou
ilkou / blockchain.js
Created November 5, 2021 23:54
concept of Blockchain in Javascript
// A block is stored as a tuple of [parent_hash, transactions, hash_itself]
const {
createHash,
} = require('crypto');
// get hash of some data
function hash(data) {
return createHash('sha256').update(data).digest('hex');
}
@ilkou
ilkou / isValidFile.js
Created September 14, 2021 19:14
Validation of files
export const isValidFile = async (file: File) => {
const contentBuffer = await readFileAsync(file);
if (!(window.FileReader && window.Blob)) {
console.error('FileReader && Blob are not supported');
}
let header = '';
const arr = new Uint8Array(contentBuffer).subarray(0, 4);
for (let i = 0; i < arr.length; i += 1) {
header += arr[i].toString(16);
@ilkou
ilkou / mimes.js
Created September 14, 2021 19:06
File extensions and mime types
export const MIMES = [
{
Extension: 'doc',
mimeType: 'application/msword',
},
{
Extension: 'docm',
mimeType: 'application/vnd.ms-word.document.macroEnabled.12',
},
{
@ilkou
ilkou / rci(react-context-initializer).js
Last active May 7, 2021 12:22
Intellij/WebStorm live template to create a React Context Component with FlowTypes
// @flow
import * as React from 'react';
import { createContext, useContext, useState } from 'react';
export const $TM_FILENAME_BASE$ = createContext();
export function use$TM_FILENAME_BASE$() {
return useContext($TM_FILENAME_BASE$);
}
@ilkou
ilkou / quine.js
Created December 10, 2020 11:56
Trying Github Gist with this simple quine in JS (self-replicating program)
(function quine() {
console.log("(" + quine.toString() + ")()");
})()