Skip to content

Instantly share code, notes, and snippets.

@SMUsamaShah
Last active February 8, 2021 16:46
Show Gist options
  • Save SMUsamaShah/43a84f3f0e9e07783e4da5d925810e0c to your computer and use it in GitHub Desktop.
Save SMUsamaShah/43a84f3f0e9e07783e4da5d925810e0c to your computer and use it in GitHub Desktop.
TIL

Linux list all procs with command args

ps -ef

Github url shortner

$ curl -i https://git.io 
    -F "url=https://github.com/smusamashah" 
    -F "code=smusamashah"
HTTP/1.1 201 Created
Location: https://git.io/smusamashah

-F is for form data. Same can be done with postman. Send a post request, put formdata in body.

Git

List and apply stash

git stash list
git stash apply <n>
git stash pop <n> # apply and remove from stash

JavaScript

setTimeout(cb, ms)

is unreliable and expensive call. Does not complete on exact given time. If used in a loop, will slow down

Off-Screen rendering improves performance

It improves rendering performance A LOT. On-Screen canvas should only be updated with whatever is there in off-screen canvas.

var ctx_onscreen = document.getElementById("cvs").getContext("2d");
var offscreen_canvas = new OffscreenCanvas(100, 100);
var ctx_offscreen = offscreen_canvas.getContext('2d');

// render everything with this ctx_offscreen

// keep updating the on-screen canvas
function renderLoop() {
    ctx_onscreen.drawImage(ctx_offscreen.canvas, 0, 0);
    requestAnimationFrame(renderLoop);
}
renderLoop();

Export canvas animation to gif or webm

https://github.com/spite/ccapture.js/

or follow this https://webrtc.github.io/samples/src/content/capture/canvas-record/ its creates a webm video file from canvas without performance hit. you can embed this video or convert it to gif later

Play video from canvas as a source

make video tag like <video playsinline autoplay></video> and

var canvas = document.querySelector('canvas');
var video = document.querySelector('video');
var stream = canvas.captureStream();
video.srcObject = stream;

Jenkins

To use Java .jar libraries in groovy, place the jar files in /usr/lib/jvm/java-1.8-openjdk/jre/lib/ext/. Then you can use import mylib.*.

Jupyter Notebook

To install a module in Jupyter Notebook for Python, use !pip install (with an exclamation mark) like below

!pip install sklearn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment