Skip to content

Instantly share code, notes, and snippets.

@orkoden
orkoden / find and replace incorrectly escaped characters for a localized string.sh
Last active August 29, 2015 14:06
Incorrectly escaped string in my localized strings files: \\"%@\\" should have been \"%@\" as it should display as "foo".
find Resources/Localizable.strings -name "*.strings" -type f -exec gsed -i 's/\\\\\"%@\\\\\"/\\\"%@\\\"/g' {} ";" -exec plutil -lint {} ";"
# needs gnu-sed to be installed for -i parameter
@orkoden
orkoden / allthecows.rb
Last active August 29, 2015 14:08
Get all the cows cowsay has to offer to say a random quote
Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }
@orkoden
orkoden / FizzBuzz in Haskell.hs
Last active August 29, 2015 14:15
FizzBuzz in Haskell that I live coded as part of a demo for hackership
data Fizzbuzz = FizzBuzz
| Fizz
| Buzz
deriving Show
fizzbuzz :: [Integer] -> String
fizzbuzz x = unlines (map fizzbuzzline x)
fizzbuzzline :: Integer -> String
fizzbuzzline x = fizzBuzzToString x (fizzBuzzFromNum x)
@orkoden
orkoden / lettermix.rb
Created March 3, 2015 13:20
Lettermix randomizes the letters in words, that are passed as arguments.
#!/usr/bin/env ruby
ARGV.each do|a|
puts "#{a}".split("").shuffle.join
end
@orkoden
orkoden / FizzBuzzWithoutIfAndModulo.m
Last active August 29, 2015 14:22
Fizzbuzz in Objective-C that works without if, modulo, lookup table
#import <Foundation/Foundation.h>
NSMutableArray* fizzbuzzreplace(NSMutableArray* numberArray, NSUInteger divider, NSString* replacementString)
{
for (NSUInteger i = divider; i < numberArray.count + 1; i = i + divider) {
[numberArray replaceObjectAtIndex:i - 1 withObject:replacementString];
}
return numberArray;
}
@orkoden
orkoden / brewpdate.sh
Last active December 17, 2015 18:49
A little script to update all currently installed programs with homebrew. Also removes old versions.
#!/bin/sh
echo "searching for updates..."
brewoutput=`brew update`
if [ "$brewoutput" == "Already up-to-date." ]
then
echo "nothing to update"
else
echo "updating..."
brewoutput=`brew upgrade --all`
if [[ "$brewoutput" == *".app bundles were installed."* ]]
@orkoden
orkoden / easyReleaseNotesWithGit.sh
Last active December 21, 2015 12:29
easy release notes with git.gets all commit messages since the last tag. useful when preparing release notes.cut is there to get rid of the commit hashes, sort is there because then all commits starting with "fix: bug 9001" or "change: will be next to each other.put into .bashrc, .profile, .zshrc depending on your shell.only works if you tag you…
# replace mate with editor of your choice
alias releasenotes="git log --oneline --no-merges `git describe --abbrev=0 --tags`..HEAD | cut -c 9- | sort | mate"
# StackView Tips
## Performance hack
### Old hack
Use a UITableViewCell's contentview. The layout will not bubble up from here. Keeps all layout restriced to that view.
Then set frame of cell.
# run with
# ruby reallyCleanXcode.rb
derivedDataFolder = Dir.glob(Dir.home + "/Library/Developer/Xcode/DerivedData/*")
moduleCache = Dir.glob("/var/folders/**/com.apple.DeveloperTools*")
FileUtils.rm_rf derivedDataFolder + moduleCache
@orkoden
orkoden / demotask.swift
Last active April 23, 2019 22:27
swift solution to codility demo task
// MissingInteger
// Find the smallest positive integer that does not occur in a given sequence.
//This is a demo task.
//
//Write a function:
//
//public func solution(_ A : inout [Int]) -> Int
//
//that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.