Skip to content

Instantly share code, notes, and snippets.

View jcubic's full-sized avatar
🎯
Focusing

Jakub T. Jankiewicz jcubic

🎯
Focusing
View GitHub Profile
@jcubic
jcubic / sw.js
Created November 8, 2021 19:09
service worker for serving files from BrowserFS
/**@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 / onRender.js
Last active July 1, 2021 14:57
onRender jquery plugin
// ---------------------------------------------------------------------------
// :: 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.");
}
@jcubic
jcubic / cert
Last active June 25, 2021 10:30
Upload SSL Certificate to DirectAdmin controlled domains
#!/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 / SVGMatrix.js
Created April 29, 2020 17:34
SVGMatrix
/*
3x3 2D Matrix
[a c e]
[b d f]
[0 0 1]
*/
var DOMException = require('domexception');
@jcubic
jcubic / bookmark.js
Last active February 17, 2021 19:38
16colo.rs Terminal ANSI rendering Bookmarklet
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 / init.java
Last active December 30, 2019 15:42
Reflection based JSON-RPC Servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.reflect.*;
import com.thetransactioncompany.jsonrpc2.*;
public class init extends HttpServlet {
public init() {
@jcubic
jcubic / git_sqllite.py
Created October 22, 2017 09:25
Create sqlite data base from git repo commits
#!/usr/bin/env python
import git
import json
import sqlite3
import re
import os
import os.path
def log(repo):
@jcubic
jcubic / cross-domain.js
Last active December 10, 2018 20:34
Cross domain ajax request without CORS using iframe and postMessage
$.fn.crossDomainRequest = function(url, method, data, fn) {
var self = this;
var receiver = self.attr('src').replace(/\/.*$/, '').replace(/^https?::\/\//, '');
function get(event) {
if (event.origin.match(receiver)) {
// event.data is response from POST
fn(event.data);
}
}
if (window.addEventListener){
@jcubic
jcubic / module.js
Last active September 3, 2018 08:32
Module definition function with namespace and dependencies
// -----------------------------------------------------------------------------
// 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 / server.py
Created February 4, 2018 18:23
Simple HTTP server for static files
#!/usr/bin/python
import socket
import re
import os
import threading
header_re = re.compile(r"(GET|POST) ([^ ]+) HTTP/", re.I)
def status(code):