Skip to content

Instantly share code, notes, and snippets.

Avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / sha256-hmac.md
Last active Oct 11, 2021
Hashing examples in different languages
View sha256-hmac.md

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@jasny
jasny / linkify.php
Last active Oct 9, 2021
PHP function to turn all URLs in clickable links
View linkify.php
<?php
/**
* Turn all URLs in clickable links.
*
* @param string $value
* @param array $protocols http/https, ftp, mail, twitter
* @param array $attributes
* @return string
*/
public function linkify($value, $protocols = array('http', 'mail'), array $attributes = array())
@jasny
jasny / mysql_splitdump.sh
Last active Sep 3, 2021
Split MySQL dump SQL file into one file per table or extract a single table
View mysql_splitdump.sh
#!/bin/bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -lt 1 ] ; then
echo "USAGE $0 DUMP_FILE [TABLE]"
exit
@jasny
jasny / icu-config
Created May 26, 2020
ICU 66.1 for Ubuntu 20.04
View icu-config
#!/bin/sh
## -*-sh-*-
#set -x
# BEGIN of icu-config-top
# Copyright (C) 2016 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
#******************************************************************************
# Copyright (C) 1999-2013, International Business Machines
# Corporation and others. All Rights Reserved.
#******************************************************************************
@jasny
jasny / tinytextindex.md
Last active Jul 6, 2021
TinyTextIndex
View tinytextindex.md

Tiny Text Index

Lightweight text indexer for PHP

Uses the dba extension (with db4)


Storing

Hello my name is Arnold and I'm not crazy. Arnold's kids are crazy though.

@jasny
jasny / unit.php
Last active Jul 6, 2021
Idea for Unit PHP extension
View unit.php
<?php
$distance = new Meter(3);
$cm = $distance->in(Centimeter::class);
ecoh $distance; // 3m
echo $cm; // 300cm
$distance == Decimeter(30); // True
$distance === Decimeter(30); // False
@jasny
jasny / flip.js
Created Mar 27, 2014
Turn text upside down with JavaScript
View flip.js
//this script is based on coding by Reverse Fad http://www.revfad.com
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}
function flipString(aString) {
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
@jasny
jasny / CrudClient.php
Last active Jul 14, 2020
Example of a CRUD controllers for new framework
View CrudClient.php
<?php
use Jasny\DB\Option\Functions as opts;
use Jasny\HttpAttributes\Request\Accept;
use Jasny\HttpAttributes\Request\ParsedBody;
use Jasny\HttpAttributes\Request\PathParam;
use Jasny\HttpAttributes\Response\ContentType;
use Jasny\HttpAttributes\Route\Delete;
use Jasny\HttpAttributes\Route\Get;
use Jasny\HttpAttributes\Route\Post;
@jasny
jasny / gen.php
Last active Jul 6, 2020
rfc:strict_operators - Generate every combination of operands and operators
View gen.php
<?php
$one = [
'arithmetic' => ['+$a', '-$a'],
'bitwise' => ['~$a'],
'incdec' => ['++$a', '--$a'],
'logical' => ['!$a'],
];
$two = [
@jasny
jasny / comparison-gotchas.php
Last active May 24, 2020
PHP comparison gotchas
View comparison-gotchas.php
<?php
/**
* `a > b > c > a` should always result in false.
*/
function all_greater($a, $b, $c)
{
return ($a > $b) && ($b > $c) && ($c > $a);
}
// Fails due to type juggling.