Skip to content

Instantly share code, notes, and snippets.

View eschmar's full-sized avatar

Marcel Eschmann eschmar

View GitHub Profile
@eschmar
eschmar / BlogCaptureXcodePlayground.swift
Last active March 5, 2023 15:54
Blog: Capture Xcode Playground SwiftUI animations as mp4
/**
* **Step 3**: Render all the frames
*
* This is the accompayning code of a blog post. Read more at https://eschmann.dev
*/
import SwiftUI
import PlaygroundSupport
struct MyExperimentalView: View {
@eschmar
eschmar / AngularGradient.swift
Created February 27, 2023 19:07
SwiftUI gradient along a circular path animation
//: A SwiftUI based playground.
import SwiftUI
import PlaygroundSupport
struct MyShape : Shape {
var startAngle: Double
var progress: Double
func path(in rect: CGRect) -> Path {
@eschmar
eschmar / Code.gs
Last active December 5, 2022 10:38
Google sheets (Apps Script) custom function to count cells with a given background color.
/**
* Counts cell values in a range if they have the given background color
* =countByColor("V16", "S12:W20")
*
* @param {String} Cell reference for color to compare as String.
* @param {String} Range to iterate through as String.
* @return {int} Count of all cells matching background color.
*/
function countByColor(cellColorToCompare, rangeToCount) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
@eschmar
eschmar / exif.sh
Last active August 15, 2020 12:38
Bash script to iterate over set of images, setting creation date
#!/bin/bash
# Whatsapp 'WhatsApp Image 2020-08-13 at 21.06.23.jpeg'
for file in ./*.jpeg; do
echo " > $file"
year=${file:17:4}
month=${file:22:2}
day=${file:25:2}
hour=${file:31:2}
minute=${file:34:2}
@eschmar
eschmar / index.twig
Created October 28, 2018 10:20
Inject the data encoded in JSON
{#
https://twitter.com/dunglas/status/1054993007332724738?s=03
Inject the data encoded in JSON in a `<script type="application/json">` tag.
Then access to this element in JS and call `JSON.parse`.
It's secure, elegant and works even with the strictest CSPs.
https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Bundle/Resources/views/SwaggerUi/index.html.twig#L11-L12
https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Bundle/Resources/public/init-swagger-ui.js#L6
#}
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@eschmar
eschmar / import.sh
Created December 22, 2014 10:03
Large MySQL dump import
# shorthand
mysql -u root <database_name> < <sql_file_path>
# long
mysql -u root -p
use <database_name>
source <sql_file_path>
# windows phpmyadmin alias
importmysql=C:\xampp\mysql\bin\mysql.exe -u root $1 < $2
@eschmar
eschmar / queries.sql
Last active January 2, 2016 20:29
Handy mysql queries
-- Average length of a text column
SELECT AVG(LENGTH(content)) AS length FROM `column` WHERE content!='';
-- Maximum length of a text column
SELECT MAX(LENGTH(content)) AS length FROM `column` WHERE content!='';