Skip to content

Instantly share code, notes, and snippets.

View kebman's full-sized avatar
Playing Ponkatris

kebman kebman

Playing Ponkatris
View GitHub Profile
@Dan-Q
Dan-Q / _no_code_page_.php
Last active May 3, 2024 08:46
Hacky PHP to produce a "blank" web page which somehow has content when viewed in Firefox. Sample page at https://danq.me/wp-content/no-code-webpage/, explanation at https://danq.me/nocode
<?php
// half-hearted CSS minification
$css = preg_replace(
array('/\s*(\w)\s*{\s*/','/\s*(\S*:)(\s*)([^;]*)(\s|\n)*;(\n|\s)*/','/\n/','/\s*}\s*/'),
array('$1{ ','$1$3;',"",'} '),
file_get_contents('linked.css')
);
// embed as a data: uri
$base64css = rtrim(strtr(base64_encode($css), '+/', '-_'), '=');
@kebman
kebman / nordics_lightning_alert.py
Last active July 7, 2023 07:07
A small script that alerts the user of lightning if it strikes within 16 km (10 miles) of your home in the Nordics, based on observations from The Norwegian Meteorological Institute.
#!/usr/bin/python3
from sseclient import SSEClient
import json
from math import sqrt
import winsound # NOTE: Windows only
from datetime import datetime, timezone, timedelta
'''
Version 2.1 (2023-07-07): A small script that alerts the user of lightning if it strikes within 16 km (10 miles) of your home position in the Nordics.
Based on lightning observations broadcast as SSE from The Norwegian Meteorological Institute, https://www.met.no/.
@corbanb
corbanb / JavaScript.sublime-build
Last active May 2, 2022 22:56
Sublime Text - Tools > Build System > New Build System
// Sublime Text - Build System for Javascript
{
"cmd": ["node", "$file"],
"selector": "source.js"
}
@bbengfort
bbengfort / cipher-func.js
Last active December 20, 2021 01:13
Encrypting and decrypting aes128 ciphers with an initialization vector in node.js.
var crypto = require('crypto');
var secret = crypto.randomBytes(24);
function encrypt(plaintext) {
var cipher = crypto.createCipher('aes-256-cbc', secret);
cipher.setAutoPadding(false);
var ciphertext = '';
for (var i=0; i < plaintext.length; i+=16) {
ciphertext += cipher.update(plaintext.substr(i, i+16), 'utf8', 'base64');
@erichonorez
erichonorez / rest_api.js
Created February 10, 2013 19:09
A simple REST API with Node.js and Express
/**
* TaskRepository class deals with task persistence
*/
function TaskRepository() {
this.tasks = [];
this.nextId = 1;
}
/**
* Find a task by id
* Param: id of the task to find