Skip to content

Instantly share code, notes, and snippets.

View webdesignberlin's full-sized avatar
:octocat:
...

Michael Raguse webdesignberlin

:octocat:
...
View GitHub Profile
<div id="ipinfo"></div>
<script>
function getip(json){
var info, container = document.getElementById('ipinfo');
try {
info = jQuery.parseJSON(json);
container.innerHTML = info.ip + "/" + info.host;
} catch(e) {
<script>
// Register the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
@webdesignberlin
webdesignberlin / client-hints-service-worker.js
Created November 6, 2015 12:34 — forked from deanhume/client-hints-service-worker.js
Service Worker & HTTP Client Hints
"use strict";
// Listen to fetch events
self.addEventListener('fetch', function(event) {
// Check if the image is a jpeg
if (/\.jpg$|.png$/.test(event.request.url)) {
// Inspect the accept header for WebP support
var supportsWebp = false;
@webdesignberlin
webdesignberlin / chat-frontend.js
Created January 5, 2016 07:34 — forked from martinsik/chat-frontend.js
Node.js chat frontend and server
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;
@function map-deep-get($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
@if (type-of($map) == 'null') { @return $map; }
}
@return $map;
}
@webdesignberlin
webdesignberlin / nginx.conf
Created February 16, 2016 13:40 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your location block(s):
#
# include cors_support;
#
# A limitation to this method is that Nginx doesn't currently send headers
@webdesignberlin
webdesignberlin / YourViewController.m
Created March 10, 2016 15:40 — forked from amster/YourViewController.m
Load a UIWebView in iOS that can also load local resources like images, CSS, and JavaScript
// An example viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadWebView];
}
// The example loader
//
// Assumes you have an IBOutlet for the UIWebView defined: @property (strong, nonatomic) UIWebView *wv;
@webdesignberlin
webdesignberlin / save-data-header.js
Created March 11, 2016 16:41 — forked from deanhume/save-data-header.js
Save-Data header service worker
"use strict";
this.addEventListener('fetch', event => {
// Save Data support
if(event.request.headers.get('save-data')){
//Return smaller images
if (/\.jpg$|.gif$|.png$/.test(event.request.url)) {
let saveDataUrl = event.request.url.substr(0, event.request.url.lastIndexOf(".")) + '-savedata' + event.request.url.substr(event.request.url.lastIndexOf("."), event.request.url.length - 1);
var DOMTokenListSupports = function(tokenList, token) {
if (!tokenList || !tokenList.supports) {
return;
}
try {
return tokenList.supports(token);
} catch (e) {
if (e instanceof TypeError) {
console.log("The DOMTokenList doesn't have a supported tokens list");
} else {
@webdesignberlin
webdesignberlin / pseudo-elements.md
Created April 4, 2016 11:50 — forked from p3t3r67x0/pseudo_elements.md
A CSS pseudo-element is used to style specified parts of an element. In some cases you can style native HTML controls with vendor specific pseudo-elements. Here you will find an list of cross browser specific pseudo-element selectors.

Styling native elements

Native HTML controls are a challenge to style. You can style any element in the web platform that uses Shadow DOM with a pseudo element ::pseudo-element or the /deep/ path selector.

video::webkit-media-controls-timeline {
  background-color: lime;
}

video /deep/ input[type=range] {