Skip to content

Instantly share code, notes, and snippets.

@elifiner
elifiner / scroll-indicators.html
Created April 30, 2019 01:11
CSS indicators for scrollable content
<html>
<style>
.div1 {
position: relative;
display: inline-block;
border: 1px solid #ccc;
}
.div1::after {
content: "";
@elifiner
elifiner / pivot.php
Created March 11, 2019 23:13
Compute simple pivot table of a CSV file
<?php
if (count($argv) < 4) {
echo "
Usage: php pivot.php <file> <column>[,<column>] <column>:<func>
Examples:
php pivot.php data.csv Type sum:Amount
php pivot.php data.csv Type,Description sum:Amount
";
@elifiner
elifiner / unserialize.php
Created February 5, 2019 03:53
Unserialize a PHP string and print as JSON or var_export
#!/usr/bin/env php
<?php
function var_export_short($var, $return = true)
{
switch (gettype($var)) {
case 'object':
return var_export_short((array) $var);
case 'array':
$keys = array_keys($var);
@elifiner
elifiner / parse-parameters.sh
Last active August 3, 2018 20:21
Parse parameters in a bash script
#!/bin/bash
[ $1 ] || set -- "-h"
while [ $1 ]; do case $1 in
-h|--help) echo "usage: $0 <args> [options]"; exit 1 ;;
-f|--force) FORCE="force" ;;
*) break ;;
esac; shift; done
echo $FORCE $@
@elifiner
elifiner / -first-last-names.md
Last active April 16, 2025 23:21
List of first names and last names for random data generation

First and last names

This gist has two files in it: first-names.txt and last-names.txt, each with 4096 names taken from some unnamed database.

Useful for generating mock data for testing or for opfuscating production data for testing.

See https://stackoverflow.com/a/50242368/15109 for some thoughts about data obfuscation.

@elifiner
elifiner / indent.php
Last active June 11, 2022 20:27
Indent and de-indent multiline strings in PHP
<?php
function dedent($str)
{
$parts = array_filter(explode("\n", $str), function($part) {
return trim($part);
});
$spaces = min(array_map(function($part) {
preg_match('#^ *#', $part, $matches);
return strlen($matches[0]);
@elifiner
elifiner / -simple-editable-html-table.md
Last active April 2, 2018 06:35
Simple editable HTML table

Simple editable HTML table

This gist implements the simplest possible editable HTML table that kinda feels a little like Excel if you aren't looking too closely.

You can move around with the arrow keys, you can edit the cell contents if you hit Enter, and if you hit Tab at the bottom right cell it adds a new line. Should be good enough for simple tabled data entry in a form that requires it.

You can see it in action here:

@elifiner
elifiner / richtext.html
Created March 31, 2018 12:00
A simple rich text editor with blot (tag) support
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pell/1.0.4/pell.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pell/1.0.4/pell.js"></script>
<script>
// adds a control to add simple blots to the text
pell.definit = pell.init;
pell.init = function(args) {
@elifiner
elifiner / var_export_short.php
Last active March 28, 2018 00:25
A condensed, non-indented, PHP-parseable representation of any PHP data
function var_export_short($var, $return = true)
{
switch (gettype($var)) {
case "object":
return var_export_short((array)$var);
case "array":
$keys = array_keys($var);
$values = array_values($var);
if ($values === $var) {
$array = implode(', ', array_map('var_export_short', $values));
@elifiner
elifiner / git-commit-size
Last active December 28, 2017 18:37
Get diff size for a list of commits
git log master..release --no-merges --format='%h' |\
while read hash; do
git show --oneline --no-patch $hash
git diff --shortstat $hash..$hash^
done