Skip to content

Instantly share code, notes, and snippets.

View svercl's full-sized avatar
🤓

Brad Svercl svercl

🤓
View GitHub Profile
@Dan-Q
Dan-Q / _no_code_page_.php
Last active October 12, 2024 16:49
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), '+/', '-_'), '=');
@ssokolow
ssokolow / escape_non_utf8_paths.rs
Last active April 11, 2024 05:42
Code for storing Rust Path/PathBuf data as valid UTF-8 (eg. JSON) strings
/* POSIX paths in JSON via escaping which
doesn't alter valid UTF-8 paths.
The trick is recognizing that JSON can store binary nulls in strings
but nulls are the only character that can't occur in POSIX paths,
so we can use it as an escape character that won't change how existing
serialized paths get interpreted.
Copyright 2018-2020, Stephan Sokolow
@JoeyBurzynski
JoeyBurzynski / 55-bytes-of-css.md
Last active October 10, 2025 02:37
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@cbaggers
cbaggers / update.lisp
Created January 27, 2016 18:10
update-swank
(defun update-swank ()
"Called from within the main loop, this keep the lisp repl
working while cepl runs"
(continuable
(let ((connection (or swank::*emacs-connection*
(swank::default-connection))))
(when connection
(swank::handle-requests connection t)))))
@brianloveswords
brianloveswords / fancy-newline.el
Last active May 18, 2019 03:39
An enhanced newline function for use with smartparens-mode.
(defun my-fancy-newline ()
"Add two newlines and put the cursor at the right indentation
between them if a newline is attempted when the cursor is between
two curly braces, otherwise do a regular newline and indent"
(interactive)
(if (and (equal (char-before) 123) ; {
(equal (char-after) 125)) ; }
(progn (newline-and-indent)
(split-line)
(indent-for-tab-command))
@en4bz
en4bz / format.cpp
Last active February 21, 2017 02:37
sprintf with C++ variadic templates
#include <iostream>
#include <sstream>
#include <tuple>
template<class Tuple, std::size_t N>
struct TuplePrinter {
static void print(const std::string& fmt, std::ostream& os, const Tuple& t) {
const size_t idx = fmt.find_last_of('%');
TuplePrinter<Tuple, N-1>::print(std::string(fmt, 0, idx), os,t);
os << std::get<N-1>(t) << std::string(fmt, idx + 1);
@niwinz
niwinz / express.cljs
Created December 26, 2014 16:16
Lightweight sugar syntax for expressjs with clojurescript.
(ns express
"Ligweight interface to requirejs."
(:refer-clojure :exclude [set get])
(:require [cljs.nodejs :as node]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^{:doc "Global express import."