Skip to content

Instantly share code, notes, and snippets.

@deathlyfrantic
deathlyfrantic / vector.php
Last active September 24, 2021 12:07
php object implementation of a standard list (not hashtable)
<?php
function vector($arg = null): Vector {
return new Vector($arg);
}
function is_vector($obj): bool {
return $obj instanceof Vector;
}
@deathlyfrantic
deathlyfrantic / mouse.vim
Created January 31, 2017 21:55
check/uncheck [x] boxes with the mouse in vim.
" this whole thing is super brittle, but was a fun experiment
function! s:string_replace(string, new_char, position)
let l:string_list = [strpart(a:string, 0, a:position)]
let l:string_list = add(l:string_list, a:new_char)
let l:string_list = add(l:string_list, strpart(a:string, (a:position + 1)))
return join(l:string_list, '')
endfunction
function! CheckThatBox()
" expiremental async job running thing with status window for neovim. never quite finished it.
function! UnmapEscKey()
unmap <Esc>
echo ''
endfunction
" log job output to a scratch buffer
function! s:LogAsyncJob(job_id, data, event)
let cur_buf_win = bufwinnr('%')
let job_buf_win = bufwinnr('job_output')
@deathlyfrantic
deathlyfrantic / linked-list.c
Created May 19, 2016 03:15
trying to learn C so i wrote a linked list
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct ListItem {
int value;
struct ListItem *next;
struct ListItem *prev;
} listitem_t;
@deathlyfrantic
deathlyfrantic / mini-framework.php
Created March 21, 2016 16:27
the start of a mini-framework for object<->db abstraction that i will not finish because it's reinvention of the wheel
<?php
function coerceToCamelCase($string)
{
$camel = "";
$i = 0;
$upper = false;
while($i < mb_strlen($string)) {
$char = $string[$i];
@deathlyfrantic
deathlyfrantic / 256_color_palette.vim
Created March 1, 2016 16:22
VimL color array that maps 256 color codes to RGB equivalents
" source: http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
" just use the cterm color code as the list index to get the gui color code
" e.g. ctermfg=237 guifg=s:palette[237]
let s:palette = [
\ '#000000', '#800000', '#008000', '#808000', '#000080', '#800080', '#008080', '#c0c0c0',
\ '#808080', '#ff0000', '#00ff00', '#ffff00', '#0000ff', '#ff00ff', '#00ffff', '#ffffff',
\ '#000000', '#00005f', '#000087', '#0000af', '#0000d7', '#0000ff', '#005f00', '#005f5f',
\ '#005f87', '#005faf', '#005fd7', '#005fff', '#008700', '#00875f', '#008787', '#0087af',
\ '#0087d7', '#0087ff', '#00af00', '#00af5f', '#00af87', '#00afaf', '#00afd7', '#00afff',
@deathlyfrantic
deathlyfrantic / tree-style-tabs.css
Last active January 5, 2016 11:59
firefox tree style tabs gnome dark theme integration hack
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
@-moz-document url("chrome://browser/content/browser.xul") {
/* from existing gnome integration css
i opened an issue on github about this so presumably it will be fixed at some point
but until then (or in case it isn't), this can be added as a stylish userstyle
%define tree #TabsToolbar.treestyletab-tabbar-toolbar[orient="vertical"]
%define treeDefault @tree@:not([treestyletab-style])
*/
@deathlyfrantic
deathlyfrantic / imagick_colorspace_constants.php
Last active August 8, 2017 14:43
get useful imagemagick colorspace constants from getImageColorspace() as opposed to mystery integers
<?php
$reflection = new \ReflectionClass("\Imagick");
$colorspaces = array_flip(
array_filter(
$reflection->getConstants(),
function ($k) {
return mb_strpos($k, "COLORSPACE") !== false;
},
ARRAY_FILTER_USE_KEY
)
@deathlyfrantic
deathlyfrantic / dom-insert-after.php
Last active February 17, 2023 12:15
why doesn't the DOM spec include an insertAfter method, srsly guys
<?php
/** Inserts a new node after a given reference node. Basically it is the complement to the DOM specification's
* insertBefore() function.
* @param \DOMNode $newNode The node to be inserted.
* @param \DOMNode $referenceNode The reference node after which the new node should be inserted.
* @return \DOMNode The node that was inserted.
*/
function insertAfter(\DOMNode $newNode, \DOMNode $referenceNode)
{
if($referenceNode->nextSibling === null) {
@deathlyfrantic
deathlyfrantic / RecursiveUtils.php
Last active October 21, 2015 16:58
miscellaneous recursive file system functions for PHP that I shouldn't have to write myself
<?php
abstract class RecursiveUtils
{
/**
* Return the entire contents of a directory as SplFileInfo objects including all subdirectories.
* @param string $path The path of the directory whose contents you want.
* @return array An array of the full paths of those contents.
*/
public static function rscandir($path)
{