Skip to content

Instantly share code, notes, and snippets.

View honsa's full-sized avatar
💭
I am just a human

honsa.ch honsa

💭
I am just a human
View GitHub Profile
@honsa
honsa / oauth.php
Created May 3, 2018 19:36
oauth php
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth/index.php');
$auth_url = $client->createAuthUrl(); ?>
<button onclick="window.location.href = '<?= $auth_url ?>' ">login</button>
@honsa
honsa / xhrInterception.js
Last active May 18, 2018 20:15
xhr interception
(function (open) {
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
this.addEventListener("readystatechange", function () {
let state = this.readyState;
console.log(this);
if (this.readyState === 4) {
//here you go
}
}, false);
@honsa
honsa / time2string.php
Last active May 31, 2018 17:01
relative time string from timestamp
function time2string($timestamp){
$now = new DateTime(date('Y-m-d H:i:m.s'));
$searched = new DateTime(date('Y-m-d H:i:m.s', $timestamp));
$diff = $searched->diff($now);
if($diff->y > 0){
if($diff->y === 1){
return 'vor einem Jahr';
} else {
return 'vor ' . $diff->y . ' Jahren';
@honsa
honsa / .htaccess
Last active May 31, 2018 16:47
gzip apache
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
@honsa
honsa / swipe-events.js
Created June 13, 2018 15:29
Detect swipe events vanilla javascript
function swipeEvents(){
// patch CustomEvent to allow constructor creation (IE/Chrome) - resolved once initCustomEvent no longer exists
if ('initCustomEvent' in document.createEvent('CustomEvent')) {
window.CustomEvent = function (event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
let evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
@honsa
honsa / guetzli.py
Last active June 29, 2018 14:16
thumbor optimizer support for guetzli
#!/usr/bin/python
# -*- coding: utf-8 -*-
# thumbor imaging service
# https://github.com/thumbor/thumbor/wiki
#guetzli compression for thumbor
#https://gist.github.com/honsa/bf972693bc1452d42acc1d87d0ce18e1
# Licensed under the MIT license:
@honsa
honsa / weather.svg
Created July 3, 2018 14:09
Displaying an animated icon for the current weather at any given location.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@honsa
honsa / index.html
Created July 4, 2018 12:31
Styled JavaScript Countdown Clock
<h1>Countdown Clock</h1>
<div id="clockdiv">
<div>
<span class="days"></span>
<div class="smalltext">Days</div>
</div>
<div>
<span class="hours"></span>
<div class="smalltext">Hours</div>
</div>
@honsa
honsa / IntersectionObserver.js
Last active October 2, 2018 18:37
Simple example implementation of the famous javascript intersection observer.
let element = document.querySelector('.element');
observer = new IntersectionObserver(callback);
observer.observe(element);
function callback(entry, observer){
if(entry[0].isIntersecting){
console.log(entry[0]);
}
@honsa
honsa / animatedScrollTo.js
Created September 12, 2018 08:18 — forked from joshbeckman/animatedScrollTo.js
ScrollTo animation using pure javascript and no jquery
document.getElementsByTagName('button')[0].onclick = function () {
scrollTo(document.body, 0, 1250);
}
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;