Skip to content

Instantly share code, notes, and snippets.

@ppscvalentin
ppscvalentin / once.js
Created May 25, 2016 12:05
Apply function once
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
@ppscvalentin
ppscvalentin / Gruntfile.js
Created July 20, 2016 09:18
Basic Grunt setup
module.exports = function(grunt) {
require('jit-grunt')(grunt);
grunt.initConfig({
path: {
'static': 'static',
'src': 'src',
'node': 'node_modules'
},
less: {
@ppscvalentin
ppscvalentin / visuallyhidden.css
Last active October 27, 2022 10:14
Screen reader
/**
* Visually hidden, but accessible
* https://css-tricks.com/places-its-tempting-to-use-display-none-but-dont/
*/
.visuallyhidden {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px; width: 1px;
margin: -1px; padding: 0; border: 0;
@ppscvalentin
ppscvalentin / queryString.js
Created July 26, 2017 19:53
queryString.js
function encodeQueryData(data) {
var ret = [];
for (let d in data)
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d]));
return ret.join('&');
}
var events = (function(){
var topics = {};
var hOP = topics.hasOwnProperty;
return {
subscribe: function(topic, listener) {
// Create the topic's object if not yet created
if(!hOP.call(topics, topic)) topics[topic] = [];
// Add the listener to queue
@ppscvalentin
ppscvalentin / debounce.js
Created August 22, 2017 08:15
debounce, throttle
// https://davidwalsh.name/function-debounce
debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
@ppscvalentin
ppscvalentin / meta.html
Created August 24, 2017 08:53
meta.html
<!doctype html>
<html lang="en" prefix="og: http://ogp.me/ns/website#">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<meta name="description" content="Description">
<!-- og -->
@ppscvalentin
ppscvalentin / attributes.js
Created December 12, 2017 08:54
attributes.js
// https://davidwalsh.name/javascript-attributes
Array.prototype.slice.call(document.getElementById("myId").attributes).forEach(function(item) {
console.log(item.name + ': '+ item.value);
});
@ppscvalentin
ppscvalentin / visibility.css
Created November 2, 2018 09:52
Visibility classes
/* visibility */
.hidden {
display: none!important;
}
@media (max-width: 599px) {
.hidden-p { display: none!important; }
}
@media (min-width: 600px) and (max-width: 899px) {
.hidden-tp { display: none!important; }
}
@ppscvalentin
ppscvalentin / font-rendering.css
Created November 19, 2018 09:27
Fix thick font rendering
/* https://stackoverflow.com/questions/28217486/font-renders-thicker-in-browsers */
body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
}