Skip to content

Instantly share code, notes, and snippets.

View nestarz's full-sized avatar
🏠
Working from home

Elias Rhouzlane nestarz

🏠
Working from home
View GitHub Profile
@nestarz
nestarz / index.js
Created June 26, 2020 02:18
Draw Extension
if (chrome.tabs) {
console.log("[XXXCUT] Background Script Loaded");
const screen = async () => {
console.log("here", chrome.tabs);
const capture = chrome.tabs.captureVisibleTab({ format: "png" }, (data) => {
console.log(data);
});
console.log(1, capture);
};
chrome.runtime.onMessage.addListener(screen);
@nestarz
nestarz / test_async_http.py
Created June 23, 2020 19:05
Async HTTP Client/Server Test with custom log
import asyncio
import http.server
import http.client
class LogHTTPHandler(http.server.SimpleHTTPRequestHandler):
log_file = open('access.log', 'w', 1)
def log_message(self, format, *args):
self.log_file.write(
f"{self.client_address[0]} - - [{self.log_date_time_string()}] {format % args}\n"
@nestarz
nestarz / grailed-is-dowwnnnwnnwnwnwnwnw.js
Created June 16, 2020 14:27
Grailed "Slogans" when down
var slogans = [
'Don\'t worry, if you can\'t cop.. nobody can.',
'Don\'t worry, the fire ain\'t going anywhere.',
'Someone uploaded something too fire.',
'Rick Owens sent us a care package.',
'Yeezy stopped by the office.',
'Pray you don\'t brick your next fit.',
'Not that your most swagless homie cares or anything.',
'Please don\'t screenshot this and tag us.',
'No, you can\'t come hang out at the office.',
@nestarz
nestarz / cache-webaudio.js
Last active June 14, 2020 18:38
Cache Webaudio Sample Assets using IndexedDB
const fetchBuffer = (url) => fetch(url).then((r) => r.arrayBuffer());
export default async (ctx, obj) => {
const db = await new Promise((r) => {
const req = indexedDB.open("assets", 1);
req.addEventListener("upgradeneeded", (e) => {
const db = e.target.result;
db.createObjectStore("audiobuffers");
r(db);
});
@nestarz
nestarz / multi-scheduler.js
Last active June 14, 2020 19:01
BPM Scheduler
const createScheduler = (ctx, state) => {
const callbacks = new Set();
const id = setInterval(() => {
const scheduleAheadTime = 0.1;
while (state.time < ctx.currentTime + scheduleAheadTime) {
callbacks.forEach((callback) => callback(state.beat, state.time));
state.beat += 1;
state.time += 60.0 / state.bpm;
}
}, 25);
@nestarz
nestarz / compress.sh
Created June 10, 2020 19:41
Compress video FFmpeg
# https://aaron.cc/ffmpeg-hevc-apple-devices/
ffmpeg -i input.avi -c:v libx265 -crf 28 -c:a aac -b:a 128k -tag:v hvc1 output.mp4
@nestarz
nestarz / TextSequence.jsx
Created June 8, 2020 20:15
TextSequence
export const TextSequence = ({
texts = ["ceci", 1000, "est", 1000, "une", 1000, "demo", 1000],
}) => {
const [text, setText] = useState();
useEffect(() => {
setTimeout(function update(i = 0) {
const data = texts[i % texts.length];
if (typeof data === "string") setText(data);
setTimeout(() => update(i + 1), typeof data === "number" ? data : 0);
});
@nestarz
nestarz / index.html
Last active June 4, 2020 15:54
Markdown + Latex Editor/Renderer
<link rel="stylesheet" href="https://unpkg.com/latex.css/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body > * {
height: 100%;
outline: none;
border: none;
}
.hidden {
visibility: hidden; /* display: none; remove history of textarea */
@nestarz
nestarz / gun-react.jsx
Created May 28, 2020 12:48
Gun React Example
import React, { useEffect } from "react";
import { useGunState, useGunSetState } from "./utils/gun-hooks.js";
const session = new Date().toISOString();
const gun = window.Gun({ peers: ["http://127.0.0.1:8765/gun"] }).get(100 * 1);
export default () => {
const [set, setSet] = useGunSetState(gun);
const [lock, setLock] = useGunState(gun.get("locked"));
const add = () => setSet("hello" + Math.random());
@nestarz
nestarz / Editable.jsx
Created May 27, 2020 13:15
Contenteditable Input with a placeholder and a validation function
export const setCaretNode = (node, index) => {
if (node.lastChild)
window
.getSelection()
.collapse(
node.lastChild,
index > 0 ? index : node.lastChild.textContent.length + index + 1
);
};