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 / example.js
Last active August 10, 2024 11:08
Parentheses matching in JavaScript
try {
console.log(balanced('()'));
console.log(balanced('(x()x)'));
console.log(balanced('(this "))))")'));
console.log(balanced('(multiple) (expressions) (in) (one) (string)'));
console.log(balanced('(x()x'));
console.log(balanced('{foo [bar]}'));
console.log(balanced('(x([)]x'));
} catch (e) {
console.log(e.message);
@jcubic
jcubic / discount.php
Last active May 17, 2024 21:57
Calculate regional discount using Parity Purchasing Power for user IP address
<?php
// Copyright (C) Jakub T. Jankiewicz
// this code is released to Public Domain with CC0 license
// created with the help from ChatGPT
$default_country = [
'name' => 'Poland',
'code' => 'PL'
];
@jcubic
jcubic / example.js
Last active November 18, 2024 14:07
Simple S-Expression (lisp) paser in JavaScript
console.log(parse(`(define (square x)
"Function calculate square of a number"
(* x x))`)[0].toString());
// ==> (define (square x) "funkcja square wywołanie (square 10) zwraca 100" (* x x))
@jcubic
jcubic / index.html
Created December 21, 2023 16:03
CSS-in-JS that supports strict CSP - PoC
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="script-src code.jquery.com 'nonce-2726c7f26c'; style-src 'nonce-2726c7f26c'" />
<title></title>
<meta name="Description" content=""/>
<link rel="shortcut icon" href=""/>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
@jcubic
jcubic / mail.py
Created April 3, 2023 09:43
Script that sends spoofed emails
#!/usr/bin/env python
from smtplib import SMTP_SSL as SMTP
from email.mime.text import MIMEText
from optparse import OptionParser
from email.Utils import formatdate
import sys
if __name__ == '__main__':
@jcubic
jcubic / index.html
Last active November 19, 2022 00:11
Server-Sent Events with Service worker issue
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
</head>
<body>
<button id="sse_start" disabled>Start</button>
<button id="sse_stop" disabled>Stop</button>
<pre id="output">Loading Service Worker</pre>
<script>
@jcubic
jcubic / cdn.md
Last active November 20, 2024 17:11
How to setup a literally free CDN
@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 / 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 / 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.");
}