Skip to content

Instantly share code, notes, and snippets.

View caroillemann's full-sized avatar

Caroline Illemann Hansen caroillemann

  • Manyone
  • Copenhagen, Denmark
View GitHub Profile
@caroillemann
caroillemann / fixExifOrientationOnJpg.js
Created September 6, 2022 11:53
Fix jpg image orientation on client-side by reading exif data
import loadImage from 'blueimp-load-image'
/**
* Fix jpg image orientation on client-side by reading exif data - inspired by: https://stackoverflow.com/a/56268674/10280454
* @param {file} file - Files to upload
* @return {file} - The file with the right orientation without exif data
*/
const fixExifOrientation = async file => {
const jpegTypes = ['image/jpg', 'image/jpeg']
if (jpegTypes.includes(file.type)) {
@caroillemann
caroillemann / dates.js
Created May 19, 2021 14:58
Snippets for date formatting
// FIX INVALID DATE STRING
// Purpose: convert invalid date string to a valid one
// Issue: This date string is not valid, so e.g. Safari can't interpret it.
const invalidDateString = '2011-04-12 00:00'
const validDateString = invalidDateString.replace(/-/g, "/")
const date = new Date(validDateString)
@caroillemann
caroillemann / findAncestor.js
Created January 20, 2021 13:02
Finds an element's closest parent that matches the provided selector string.
function findAncestor(el = null, selector) {
if (el.closest) {
return el.closest(selector);
}
// IE9+ polyfill
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}
var matches = el.matches || el.matchesSelector;
@caroillemann
caroillemann / scrim-gradient.scss
Last active December 12, 2023 10:17 — forked from matthewbeta/scrim-gradient.scss
A SCSS function for creating scrim gradients with alpha start vaue
/*
A SCSS function for creating scrim gradients
Inspired by Andreas Larson - https://github.com/larsenwork
https://css-tricks.com/easing-linear-gradients/
*/
@function scrim-gradient($startColor: $color-black, $direction: 'to bottom', $startAlpha: 1) {
$scrimCoordinates: (
0: 1,
@caroillemann
caroillemann / Root.plist
Last active April 6, 2021 02:50 — forked from hujunfeng/Root.plist
Add version in Settings.bundle for iOS apps
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>