Skip to content

Instantly share code, notes, and snippets.

@peponi
peponi / detect-android-stock-browser.js
Created January 13, 2016 13:03
detect android stock browser. Adds class "is-android-stock-browser" to the html element. You will need this only in rare cases. For example: text-rendering bug with webfonts in Android 4.x.
(function(){
/*
Use this only if really really necessary.
This plugin tries to detect android stock browser.
Place it in the head tag. And after Modernizr.
https://developer.chrome.com/multidevice/user-agent#webview_user_agent
*/
@peponi
peponi / detect-orientation.js
Created January 13, 2016 13:03
A small helper, which detects orientation of viewport. Sets 'is-landscape' or 'is-portrait' to the html element.
'use strict';
(function(){
window.NIJS = window.NIJS || {};
NIJS.detection = NIJS.detection || {};
var html = document.getElementsByTagName('html')[0],
removeClass = function(str, className){
var classArr = str.split(' '),
@peponi
peponi / gulp-task-to-create-git-tags.js
Created January 13, 2016 13:46
a simple gulp task to set & overwrite git tags on remote
// set a git tag & overwrite if already set
gulp.task('push-tag', function(cb) {
if(process.argv[3] !== '--tag' ) {
console.error('ERROR: no "--tag" parameter found');
} else if (process.argv[4] == undefined ) {
console.error('ERROR: no tag name found in parameter');
} else {
exec( 'git tag -d ' + process.argv[4] +
';git push origin :refs/tags/' + process.argv[4] +
@peponi
peponi / device_metrics.scss
Created January 19, 2016 14:31
lsit of constans for device metrics ios & android
/* GENERAL DEVICE CONSTANTS
##################################################################################################################### */
/*
* iOS
*/
// iOS metrics
$ios-status-bar-height: em-calc(20);
$ios-nav-bar-height: em-calc(44);
@peponi
peponi / GetTimeDiff.php
Created August 22, 2012 13:12
Convert UNIX timestamp to days hours minute seconds
<?php
function GetTimeDiff($timestamp)
{
$how_log_ago = '';
$seconds = time() - $timestamp;
$minutes = (int)($seconds / 60);
$hours = (int)($minutes / 60);
$days = (int)($hours / 24);
if ($days >= 1) {
$how_log_ago = $days . ' day' . ($days != 1 ? 's' : '');
@peponi
peponi / store.js
Created October 2, 2018 12:29
simple one level immutable store object
const store = {
storageIndex: undefined,
debug: false,
state: Object.freeze({
}),
setState(keyword, value) {
if (this.debug) console.log(`STATE: ${keyword}:`, value); // eslint-disable-line no-console
const newObject = Object.assign({}, this.state, { [keyword]: value });
this.state = Object.freeze(newObject);
if (this.storageIndex) localStorage.setItem(this.storageIndex, JSON.stringify(newObject));
@peponi
peponi / README.md
Last active October 17, 2018 12:21
prevent doubeled objects in array
const l = localStorage
const crappyStore = {
get: (key) => JSON.parse(l.getItem(key)),
set: (key, data) => l.setItem(key, JSON.stringify(data)),
rm: (key) => l.removeItem(key),
getKeysFor: (prefix) => {
const ret = []
for (let key in l) {
ret.push(key)
@peponi
peponi / is.js
Last active May 6, 2019 12:36
is.js - es6 - just browser detection, nothing elese
// based on https://github.com/arasatasaygin/is.js/blob/master/is.js
// this is a cut off minimal version
const userAgent = (navigator && navigator.userAgent.toLowerCase()) || '';
const vendor = (navigator && navigator.vendor || '').toLowerCase();
// build a 'comparator' object for various comparison checks
const comparator = {
'<': (a, b) => a < b,
'<=': (a, b) => a <= b,
@peponi
peponi / details.polyfill.js
Last active May 6, 2019 12:41
details element polyfill for IE11, supoorts elements inside summary
/**
* based on
* @url https://github.com/rstacruz/details-polyfill
* @todo https://www.sitepoint.com/fixing-the-details-element/
* @todo https://www.smashingmagazine.com/2014/11/complete-polyfill-html5-details-element/
*/
const detailsPolyfillEs6 = ({
CSS_CLASS = 'no-details',
CSS_STRING = false,