Skip to content

Instantly share code, notes, and snippets.

View ljungmark's full-sized avatar
🍻
/dance

ʟᴊᴜɴɢᴍ•ʀᴋ ljungmark

🍻
/dance
View GitHub Profile
@ljungmark
ljungmark / partial_match.php
Created September 23, 2016 17:14
Perform partial match to string values in an array
<?php
function partial_match($needle, $haystack) {
if(!is_array($haystack)) return false;
foreach ($haystack as $key=>$item) {
if (strpos($item, $needle) !== false) return true;
}
return false;
}
@ljungmark
ljungmark / ip4_to_hex.php
Created September 23, 2016 17:15
Convert a UA provided IPv4-address to it's hexadecimal value
<?php
function ip4_to_hex($ip_address = null) {
if ($ip_address === null || filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) return 'Unable to read IP address';
$fragments = explode('.', $ip_address);
return sprintf('%02x%02x%02x%02x', $fragments[0], $fragments[1], $fragments[2], $fragments[3]);
}
print ip4_to_hex($_SERVER['REMOTE_ADDR']);
@ljungmark
ljungmark / readable_filesize.php
Created September 23, 2016 17:15
Print the (humanly) readable size of arbitrary file
<?php
function readable_filesize($file = null, $decimals = 2) {
if ($file === null) return 'Unable to read file';
$sizes = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($file) - 1) / 3);
return sprintf("%.{$decimals}f", $file / pow(1024, $factor)) . @$sizes[$factor];
}
print readable_filesize(filesize('example.zip'));
@ljungmark
ljungmark / mandatory_parameter.js
Created September 24, 2016 01:38
Enforcing mandatory parameters
function mandatory() {
throw new Error('Missing parameter');
}
function foo(mustBeProvided = mandatory()) {
return mustBeProvided;
}
@ljungmark
ljungmark / Empty HTML template
Last active May 17, 2017 16:59
Basic HTML5 Template
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Basic HTML5 Template</title>
<link rel="stylesheet" href="css/styles.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
</head>
@ljungmark
ljungmark / object-watch.js
Created May 17, 2017 16:59 — forked from eligrey/object-watch.js
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/

Keybase proof

I hereby claim:

  • I am ljungmark on github.
  • I am ljungmark (https://keybase.io/ljungmark) on keybase.
  • I have a public key ASDUf2JnEUvsMXMhULkB5OOM-iUXnPUEpdtCD70nd8st9Qo

To claim this, I am signing this object:

.selector {
font-size: calc(14px + (100vw / 50));
}
@media screen and (min-width: 1200px) {
.selector {
font-size: calc(14px + (1200px / 50));
}
}
sudo chown -R $(whoami):admin /usr/local
curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit