Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jakub T. Jankiewicz jcubic

🎯
Focusing
View GitHub Profile
@jcubic
jcubic / sw.js
Created Nov 8, 2021
service worker for serving files from BrowserFS
View sw.js
/**@license
* ___ ___ _____ __ __ _ _____ _ _
* / __|_ _|_ _| \ \ / /__| |__ |_ _|__ _ _ _ __ (_)_ _ __ _| |
* | (_ || | | | \ \/\/ / -_) '_ \ | |/ -_) '_| ' \| | ' \/ _` | |
* \___|___| |_| \_/\_/\___|_.__/ |_|\___|_| |_|_|_|_|_||_\__,_|_|
*
* this is service worker and it's part of GIT Web terminal
*
* Copyright (c) 2018 Jakub Jankiewicz <http://jcubic.pl/me>
* Released under the MIT license
@jcubic
jcubic / bookmark.js
Last active Feb 17, 2021
16colo.rs Terminal ANSI rendering Bookmarklet
View bookmark.js
javascript:(function(next) {
/**
* Bookmarklet that will create terminal with ANSI rendering
* on 16colo.rs website (individual ANSI file)
*
* Copyright (C) Jakub T. Jankiewicz <https://jcubic.pl>
* Released under MIT license
*/
if (window.jQuery) {
return next(window.jQuery);
@jcubic
jcubic / onRender.js
Last active Jul 1, 2021
onRender jquery plugin
View onRender.js
// ---------------------------------------------------------------------------
// :: execute callback function when shiny output element is modified
// :: the callback can be called multiple times if you use option onTime: false
// :: you can also use check option with function that will be check if
// :: before executing callback and removing observer
// ---------------------------------------------------------------------------
$.fn.onRender = function(callback, options) {
if (this.length === 0) {
throw new Error("Element doesn't exists! Try to wait until it's added to DOM.");
}
View SVGMatrix.js
/*
3x3 2D Matrix
[a c e]
[b d f]
[0 0 1]
*/
var DOMException = require('domexception');
@jcubic
jcubic / r-shell.js
Last active Aug 13, 2021
JavaScript bookmark that can be used to open interactive R shell in shiny app
View r-shell.js
javascript:(function($) {
var handlers = [];
if (typeof Shiny !== 'undefined') {
Shiny.addCustomMessageHandler("__EVAL__", function(data) {
handlers.forEach(function(handler) {
handler(data);
});
});
}
var index = 0;
@jcubic
jcubic / module.js
Last active Sep 3, 2018
Module definition function with namespace and dependencies
View module.js
// -----------------------------------------------------------------------------
// Copyright (c) 2018 Jakub Jankiewicz
// Released under MIT license
//
// generic namespace generator the constructor should declare private functions
// and variables and return public api, the module is created when all dependecies
// are resolved (all modules are created)
//
// @param namespace dot separated namespace that will be added to window object
// @param dependencies array of string (dependencies) can be empty array
@jcubic
jcubic / cert
Last active Jun 25, 2021
Upload SSL Certificate to DirectAdmin controlled domains
View cert
#!/bin/bash
output=$(mktemp);
sudo certbot certonly --manual --expand --manual-public-ip-logging-ok \
--preferred-challenges http -n \
-d <LIST OF COMMA SEPARATED DOMAINS AND SUBDOMAINS>\
--manual-auth-hook ./cert.py --agree-tos --email <EMAIL ADRESS> 2>&1 | tee $output
grep "Certificate not yet due for renewal" $output > /dev/null || \
@jcubic
jcubic / server.py
Created Feb 4, 2018
Simple HTTP server for static files
View server.py
#!/usr/bin/python
import socket
import re
import os
import threading
header_re = re.compile(r"(GET|POST) ([^ ]+) HTTP/", re.I)
def status(code):
@jcubic
jcubic / css.js
Created Jan 24, 2018
Monkey patch for jQuery css to handle custom properties aka css variables
View css.js
$.fn.css = (function(css) {
return function fn(key, value) {
var self = this;
if (arguments.length == 1 && $.isPlainObject(arguments[0])) {
var data = arguments[0];
Object.keys(data).forEach(function(key) {
fn.call(self, key, data[key]);
});
} else if (key.match(/^\s*--/)) {
if (typeof value === 'undefined') {
@jcubic
jcubic / compile
Last active Jun 24, 2020
POC for Emscripten Async code + jQuery Terminal
View compile
emcc -o main.html -s FETCH=1 -s NO_EXIT_RUNTIME=0 main.c