Skip to content

Instantly share code, notes, and snippets.

View bobbykjack's full-sized avatar
🏠
Working from home

Bobby Jack bobbykjack

🏠
Working from home
View GitHub Profile
function scale_photos()
{
$('#thumbs li').each(function() {
scale_photo($(this));
});
}
function scale_photo($el)
{
var width = $el.width();
@bobbykjack
bobbykjack / rgb.php
Last active August 29, 2015 14:20
Tiny script to convert CSS rgb color syntax into hexadecimal
if (preg_match('/^rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)$/', $_GET['rgb'], $m) && count($m) == 4)
{
echo '#'.join('', array_map(function($n) { return str_pad(dechex($n), 2, '0', STR_PAD_LEFT); }, array_slice($m, 1)));
}
@bobbykjack
bobbykjack / visit-nodes-iterative.js
Created February 10, 2019 17:02
Iterative approach to walking a DOM tree in javascript
function visit_nodes_iterative(node) {
node = node || document;
do
{
/* Do something with node here */
node = node.firstChild || node.nextSibling || function() {
while ((node = node.parentNode) && !node.nextSibling);
return node ? node.nextSibling : null;
@bobbykjack
bobbykjack / config.json
Created June 21, 2021 15:49
Example config file for lingth
{
"max_length": 80,
"tab_width": 4,
"replace_tabs": true,
"show_content": true,
"show_filenames": null,
"show_line_numbers": true,
"show_length": true
}
<?php
if (($arg = array_shift($args)) == '--') {
break;
}
<?php
if ($arg == "--help") {
fwrite(STDOUT, usage(true));
exit(0);
}
<?php
for ($ch = 1; $ch < strlen($arg); $ch++) {
switch ($arg[$ch]) {
case 'c': $opts['show_content'] = false; break;
case 'm': $opts['max_length'] = handle_arg(substr($arg, $ch), $args); break;
//...
}
}
<?php
while (count($args) && $args[0][0] == "-") {
//...
}
<?php
fwrite(STDERR, "bad error: no config file. install one.\n");
<?php
exit(ERR_BAD_CONFIG);