Skip to content

Instantly share code, notes, and snippets.

@pbatey
pbatey / spinner-spin.css
Last active March 27, 2018 07:23
CSS to add steps to font-awesome's spinner icon (fa fa-spinner fa-spin)
@-webkit-keyframes spinner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@-moz-keyframes spinner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@-o-keyframes spinner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@-ms-keyframes spinner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes spinner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.fa-spinner.fa-spin {
-webkit-animation: spinner-spin 1s steps(8) infinite;
-moz-animation: spinner-spin 1s steps(8) infinite;
-o-animation: spinner-spin 1s steps(8) infinite;
@pbatey
pbatey / q2m-example.js
Last active March 13, 2019 00:38
An example of an express route that uses query-to-mongo
var express = require('express')
var mongoskin = require('mongoskin')
var ObjectID = require('mongodb').ObjectID
var query2m = require('query-to-mongo')
// attach db to the router
var db = mongoskin.db('mongodb://localhost:27017/mydb', {safe: true})
var router = express.Router()
router.db = db
router.use(function (req, res, next) {
@pbatey
pbatey / progress.sh
Created June 21, 2019 15:23
Bash script to display progress (to stderr) by counting lines from stdin.
#!/bin/bash
#
# Displays progress (to stderr) by counting lines from stdin.
#
# Usage: <command> | progress.sh <expected-line-count> > <file>
#
total=$(( ${1:-0} ))
number=0
@pbatey
pbatey / uuid.c
Last active August 13, 2019 16:57
UUID RFC 4122 Version 4 (random) generator
// UUID RFC 4122 Version 4 (random)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void random_chars(char buffer[], int len) {
for (int i = 0; i < len; i++) {
sprintf(buffer + i, "%X", rand() % 16);
}
@pbatey
pbatey / Makefile
Created August 13, 2019 23:04
Makefile that generates version.json from git
# get version info from git (look for tag like 'v1.0')
GIT_VERSION = $(shell git describe --match "v[0-9]*")
GIT_BUILD = $(shell git describe --match "v[0-9]*" --long --dirty)
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_COMMIT_LONG = $(shell git rev-parse HEAD)
define VERSION_BODY
# this file generated by build process
{
"version": "${GIT_VERSION}",
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* Flattens a Map
*/
public class Flattener {
static public void process(Map<String, Object> target) {
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
import java.util.Map;
import static org.junit.Assert.*;
public class FlattenerTest {
@Test
@pbatey
pbatey / responsive-semantic-ui.css
Last active March 29, 2020 19:21 — forked from bl4ck5un/responsive-semantic-ui.css
Responsive helpers (mobile-only etc.) for semantic-ui
/* Semantic UI has these classes, however they're only applicable to*/
/* grids, containers, rows and columns.*/
/* plus, there isn't any `mobile hidden`, `X hidden` class.*/
/* this snippet is using the same class names and same approach*/
/* plus a bit more but to all elements.*/
/* see https://github.com/Semantic-Org/Semantic-UI/issues/1114*/
/* Portrait */
@media only screen and (max-width: 414px) {
@pbatey
pbatey / vault-cp
Last active September 28, 2021 02:19
Copy values from one Hashicorp Vault path to another (works with Vault v1.1.2)
#!/usr/bin/env bash
tmp=$(mktemp -d)
trap "{ rm -rf $tmp; }" EXIT
# ensure we were given two command line arguments
if [[ $# -ne 2 ]]; then
echo 'usage: vault-cp SOURCE DEST' >&2
exit 1
fi
@pbatey
pbatey / fetch.js
Last active July 8, 2020 03:01
Simple node function to get a url
const http = require('http')
const https = require('https')
async function fetch(url, options={rejectUnauthorized: false}, timeout=3000, log=true) {
await new Promise((resolve, reject) => {
const req = (/^https/.test(url) ? https : http)
.get(url, options, res => {
let data = ''
res.on('data', chunk => data+=chunk)
res.on('end', () => {log && console.log(data); resolve(data)})