Skip to content

Instantly share code, notes, and snippets.

View ralfebert's full-sized avatar

Ralf Ebert ralfebert

View GitHub Profile
import SwiftUI
class DemoModel : ObservableObject {
enum State {
case value(Date)
}
@Published var counter = 0
@Published var state = State.value(Date())
@ralfebert
ralfebert / create
Last active December 11, 2020 13:13
Create and open a file from the shell using simple templates
#!/usr/bin/env ruby
# Create and open a file from the shell using simple templates
# https://gist.github.com/ralfebert/cdc30dbc9d2c2356d8f9b6b7c1492888/edit
require 'date'
require 'shellwords'
require 'ostruct'
require 'optionparser'
@ralfebert
ralfebert / ArrayWith.swift
Last active April 6, 2020 09:23
List of random numbers with a given sum
func arrayWith(count: Int, sum : Int) -> [Int] {
assert(count >= 1)
var result = [sum]
while result.count < count {
let randomIndex = result.indices.randomElement()!
let v = Int.random(in: 0...result[randomIndex])
result[randomIndex] -= v
result.append(v)
}
return result
@ralfebert
ralfebert / slice.py
Last active April 12, 2021 08:29
Export images from Sketch to xcasset (by @ryangomba)
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
import json
import re
import time
from distutils.spawn import find_executable
@ralfebert
ralfebert / CompareImages.swift
Last active June 28, 2023 03:11 — forked from SheffieldKevin/compareimages.swift
A couple of swift functions for comparing two CGImage using CIImage in OS X
import CoreGraphics
import CoreImage
func imageMetadataString(image: CGImage) -> String {
return "\(image.width)x\(image.height) bitsPerComponent:\(image.bitsPerComponent) bytesPerRow:\(image.bytesPerRow) bitsPerPixel:\(image.bitsPerPixel)"
}
/**
@brief Returns the maximum difference of pixel values in the image.
@discussion Assumes doImagesHaveSameMeta has already returned true on
@ralfebert
ralfebert / generate_storyboard_constants.rb
Last active May 29, 2019 21:31
Generate Swift constants for Xcode storyboards containing cell reuse identifiers, segue identifiers and storyboard identifier. More information: https://www.ralfebert.de/storyboard-constants/
#!/usr/bin/env ruby
require 'nokogiri'
def show_usage(msg = nil)
puts "#{msg}\n\n" if msg
puts "Usage:\n\t#{$PROGRAM_NAME} [storyboard_file]"
exit(0)
end
@ralfebert
ralfebert / xcode_set_development_language_de.rb
Last active May 16, 2023 07:07
Ruby script that uses cocoapods Xcodeproj to set development_region / known_regions of an Xcode project to German
#!/usr/bin/env ruby
require 'fileutils'
require 'xcodeproj'
unless ARGV.count == 2
puts "Usage: xcode_set_development_region.rb [project] [region]"
exit(1)
end
From 5366b677f1f7a1053de5904f96ba5108ffaf8953 Mon Sep 17 00:00:00 2001
From: Ralf Ebert <info@ralfebert.de>
Date: Thu, 7 May 2015 23:33:01 +0200
Subject: [PATCH] Fix for #844: Incompatibility haml (4.0.6) -> sprockets
(3.0.3) causing error 'wrong number of arguments' for inline :sass filter in
haml template
---
lib/haml/sass_rails_filter.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@ralfebert
ralfebert / swift-kvo-example.swift
Last active October 18, 2020 21:41 — forked from correia/swift-kvo-example.swift
Swift 1.1: dynamic for observable properties neccessary, observeValueForKeyPath signature changed
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
git config --global alias.lg "log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr %an)%Creset' --abbrev-commit --date=relative"