Skip to content

Instantly share code, notes, and snippets.

View juji's full-sized avatar
💭
feeling awesome

Tri Rahmat Gunadi juji

💭
feeling awesome
View GitHub Profile
@juji
juji / cleanUTF8.js
Last active April 21, 2017 07:43
clean non utf8 character
function cleanUTF8(str){
return str.replace(/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]|[\x00-\x7F][\x80-\xBF]+|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/g,'')
.replace(/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/g,'');
}
@juji
juji / server.sh
Last active May 31, 2017 06:37
bash 5 line server
#!/usr/bin/env bash
# usage:
# ./server.sh [port] [response]
#
RESPONSE="HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n${2:-"OK"}\r\n"
while { echo -en "$RESPONSE"; } | nc -q 0 -l -p "${1:-8080}"; do
echo "================================================"
echo "you can do stuff on request"
@juji
juji / pandoc-svg.py
Created July 22, 2017 19:53 — forked from jeromerobert/pandoc-svg.py
Pandoc filter to create PDF files from SVG
#! /usr/bin/env python
"""
Pandoc filter to convert svg files to pdf as suggested at:
https://github.com/jgm/pandoc/issues/265#issuecomment-27317316
"""
__author__ = "Jerome Robert"
import mimetypes
import subprocess
@juji
juji / deploy.sh
Created December 14, 2017 12:40
git deploy script
#!/bin/bash
if [[ "$1" == "" ]]; then
echo 'usage: deploy <origin> <branch>'
exit
fi
if [[ "$2" == "" ]]; then
echo 'usage: deploy <origin> <branch>'
exit
@juji
juji / hex2rgba.js
Last active March 9, 2021 04:10
hex to rgba
(str, alpha) => {
if(!/^#([A-Fa-f0-9]{3}){1,2}$/.test(str))
throw new Error('Bad hex')
let c = str.substring(1).split('')
if(c.length === 3) c = [c[0], c[0], c[1], c[1], c[2], c[2]];
c = '0x'+c.join('');
@juji
juji / sshperm
Created September 20, 2023 21:11
ssh permission
cd ~ && chmod 600 ~/.ssh/* && chmod 700 ~/.ssh && chmod 644 ~/.ssh/*.pub
@juji
juji / easeOutElastic.js
Last active November 24, 2023 14:41
create easeOutElastic tween in css keyframes
function easeOutElastic(x) {
const c4 = (2 * Math.PI) / 3;
return x === 0
? 0
: x === 1
? 1
: Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
}
@juji
juji / image-resize.js
Last active November 24, 2023 14:45
Resize images using sharp, convert them to webp
const fs = require('fs/promises')
const sharp = require('sharp')
// this will create 2 images
// one with 1200 width and one with 600 width
// it will place them in the current directory
// note that the original image(s) will be expected to be png
@juji
juji / fpsMeter.js
Created December 12, 2023 21:09 — forked from capfsb/fpsMeter.js
JavaScript FPS meter - Calculating frames per second
fpsMeter() {
let prevTime = Date.now(),
frames = 0;
requestAnimationFrame(function loop() {
const time = Date.now();
frames++;
if (time > prevTime + 1000) {
let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
prevTime = time;
@juji
juji / detect-dark-mode.js
Created April 27, 2024 18:03
Detect dark mode
((w,d) => {
w && d &&
w.matchMedia('(prefers-color-scheme:dark)')?.matches &&
d.getElementsByTagName('html')[0]?.classList.add('dark')
})(window,document)