Skip to content

Instantly share code, notes, and snippets.

@DaveKin
DaveKin / json_uniq.sql
Last active October 24, 2023 18:25
SQL function to remove duplicate entries from a JSON array. Based on MYSQL 5.7+
CREATE FUNCTION JSON_UNIQ(arr JSON) RETURNS json
BEGIN
SET @arr = arr;
SET @a_length = JSON_LENGTH(@arr);
SET @loop_index = @a_length;
WHILE @loop_index >= 0 DO
SET @item = JSON_UNQUOTE(JSON_EXTRACT(@arr, concat('$[',@loop_index,']')));
@DaveKin
DaveKin / filterobject.json
Last active February 19, 2018 09:43
A compound data filter representation in json
{
"operator": "and",
"expressions": [
{
"operator": "and",
"expressions": [
{
"field": "a",
"condition": { ">": 10 }
},
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment-with-locales.min.js"></script>
on touch/tap
if item not active
activate item (show submenu)
else
navigate link
on click
navigate link
on mouseenter
@DaveKin
DaveKin / parseQueryString.js
Created May 3, 2016 13:18
function to parse the querystring into a JSON object
export function() {
var items = location.search.slice(1).split('&');
var obj = {};
items.forEach(function(item) {
item = item.split('=');
obj[item[0]] = decodeURIComponent(item[1] || '');
});
return JSON.parse(JSON.stringify(obj));
}
{
"typog": [
{
"font-family": "Baskerville,Garamond,Georgia,Times,serif",
"font-size": "16px",
"font-weight": "700",
"font-variant": "normal",
"font-style": "normal",
"color": "rgb(255, 255, 255)",
"text-transform": "none",
@DaveKin
DaveKin / testform.html
Last active December 31, 2015 12:33
HTML form with pretty much everything in it
<form>
<fieldset>
<legend>Form Fields</legend>
<div>
<label for="text-input">Text input</label>
<input id="text-input" type="text">
</div>
<div>
<label for="text-input-placeholder">Text input with placeholder</label>
<input id="text-input-placeholder" type="text" placeholder="I'm placeholder text">
@DaveKin
DaveKin / _propmap.scss
Last active February 22, 2023 13:05
Utility SASS mixin to convert a map of property names and values to CSS
/**
* Converts a SASS map of css property names and values into CSS output.
* Properties named `description` will have their value inserted as comments.
*
* Nested maps will be processed recursively.
*
* @param {map} $map the map of properties to output
*/
@mixin map-to-props($map){
@if type-of($map) == map {
@DaveKin
DaveKin / selectors1.css
Created November 18, 2015 15:42
test selector counts
.a,.b,.c,.d,.e{
display: block;
color: red;
}
.f,.g{
display: inline;
}
.b,.f{
color: green;
}
@DaveKin
DaveKin / base-elements.scss
Last active November 11, 2015 14:26
blank scss for building base HTML5 element styles - good for styling editorial content
/* Base element styles */
// The root element
html {
// root element
}
// Sections
body {
// document body