Skip to content

Instantly share code, notes, and snippets.

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

Michael Raguse webdesignberlin

:octocat:
...
View GitHub Profile
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 / 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);
@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 / 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
@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 / 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;
@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;
<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);
});
<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) {
# Bash script to convert a GIF to a video
# Only works with const framerate gifs
# Requires ffmpeg and imagemagick
# Modified from https://www.npmjs.com/package/videofy
function gif2video() {
fps="$(identify -format '%T\n' $@ | tail -1 | awk '{ print 100/$1 }')"
echo "GIF FPS: $fps"
convert "$@" gif2video_tmp_%05d.jpg
ffmpeg -f image2 -r $fps -i gif2video_tmp_%05d.jpg -c:v libx264 "$@.mp4"