Skip to content

Instantly share code, notes, and snippets.

View Simsso's full-sized avatar

Timo Denk Simsso

View GitHub Profile
@Simsso
Simsso / min-and-max-width.css
Created May 6, 2016 08:35
Bootstrap Grid CSS Media Queries
/* Extra small devices only (phones, less than 768px) */
@media (max-width: 767px) { ... }
/* Small devices only (tablets, @screen-sm-min) */
@media (min-width: 768px) and (max-width: 991px) { ... }
/* Medium devices only (desktops, @screen-md-min) */
@media (min-width: 992px) and (max-width: 1199px) { ... }
/* Large devices only (large desktops, @screen-lg-min) */
@Simsso
Simsso / bootstrap-accordion-toggle-events.js
Last active May 10, 2016 09:07
Changes the class of a Bootstrap accordion panel (.panel) depending on it's state (either collapsed or expanded)
$('.panel').on('hidden.bs.collapse', function () {
$(this).addClass('collapsed');
}).on('show.bs.collapse', function () {
$(this).removeClass('collapsed');
});
@Simsso
Simsso / map.js
Created May 10, 2016 09:05
Maps a value from an input to an output boundary
function map(x, inMin, inMax, outMin, outMax) {
return (x-inMin) * (outMax-outMin) / (inMax-inMin) + outMin;
}
@Simsso
Simsso / show-error-code.ino
Created May 16, 2016 10:22
Shows the given error code in binary format at the passed pin
// Show error code
// Shows the given error code in binary format at the passed pin
// A short blink represents a binary "0", long blink a binary "1".
// MSB first
//
// @param uint8_t code: The error code to "blink", [0;255]
// @param uint8_t pin: The output pin to use, default: 13
//
// @return void
void showErrorCode(uint8_t code, uint8_t pin = 13) {
@Simsso
Simsso / bootstrap-modal-events.md
Last active January 24, 2018 21:02
List of Bootstrap modal events with description
  • show.bs.modal: fired just before the modal is open.

  • shown.bs.modal: fired after the modal is shown.

  • hide.bs.modal: fired just before the modal is hidden.

  • hidden.bs.modal: fired after the modal is closed.

  • loaded.bs.modal: fired when remote content is successfully loaded in the modal’s content area using the remote option mentioned above.

@Simsso
Simsso / smooth-scroll.js
Created May 17, 2016 11:25
Smooth scrolling of links like <a href="#bla"> with possible user interruption
// smooth scrolling of links like <a href="#bla">
var $viewport = $('html, body');
$('a[href*="#"]:not([href="#"])').on('click', function(e) {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$viewport.animate({
scrollTop: target.offset().top // scroll to target
}, 1000);
@Simsso
Simsso / pubsub.js
Last active April 9, 2019 11:04 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
// events - a super-basic Javascript (publish subscribe) pattern
const events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@Simsso
Simsso / sort-array-by-date.js
Created August 1, 2016 01:35
Sort Array of Objects by Date
array.sort(function(a,b){
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
return new Date(b.date) - new Date(a.date);
});
@Simsso
Simsso / browser-notification.js
Created August 1, 2016 04:05
Browser Notification
function showBrowserNotification(text) {
// check if the browser supports notifications
if (!("Notification" in window)) {
// no support
}
// check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
var notification = new Notification(text);
}
@Simsso
Simsso / plot.tex
Last active January 4, 2017 16:04
Simple plot with tikz for LaTeX documents
\begin{tikzpicture}
\pgfplotsset{
scale only axis,
}
\begin{axis}[
%axis x line*=bottom,
%axis y line*=left,
xlabel=$A$,