Skip to content

Instantly share code, notes, and snippets.

View Sega-Zero's full-sized avatar

Сергей Галездинов Sega-Zero

  • Nizhnekamsk
View GitHub Profile
@Sega-Zero
Sega-Zero / copy_ffmpeg.sh
Created January 8, 2016 21:05
Script copies ffmpeg binaries that are built with brew into a specified folder and makes those binaries to be able to run from the app bundle. More info on http://sega-zero.tumblr.com/post/136899723544/ffmpeg-dylibs
#install ffmpeg if it is not installed
(brew list -1 | grep "ffmpeg" >/dev/null) || brew install ffmpeg
#update your ffmpeg distribution to the latest version
brew outdated ffmpeg || brew upgrade ffmpeg
#cleanup the destination folder
for file in `ls ffmpeg/*`; do rm -f $file; done;
#determine the last local ffmpeg version
@Sega-Zero
Sega-Zero / TrainAnimationView.swift
Created February 16, 2020 10:36
View with waiting animation that seems like a train on a railroad
class TrainAnimationView: UIView {
@IBInspectable var railwayBlockSize: CGSize = CGSize(width: 20.0, height: 10.0) { didSet { self.setupSublayers() } }
@IBInspectable var railwayBlockOffset: CGFloat = 5 { didSet { self.setupSublayers() } }
@IBInspectable var trainSize: CGSize = CGSize(width: 45.0, height: 10.0) { didSet { self.setupSublayers() } }
@IBInspectable var trainStartColor: UIColor = UIColor(219, 69, 58) { didSet { self.setupSublayers() } }
@IBInspectable var trainEndColor: UIColor = UIColor(219, 58, 106) { didSet { self.setupSublayers() } }
@IBInspectable var railwayBlockColor: UIColor = UIColor.gray.withAlphaComponent(0.5) { didSet { self.setupSublayers() } }
@IBInspectable var isAnimating: Bool = false { didSet { self.setupSublayers() } }
@Sega-Zero
Sega-Zero / TestSample.swift
Last active May 1, 2016 00:08
Example structures for stress-testing a Cereal library
enum SerializationError: ErrorType {
case IncorrectData
case FileNotExists
}
extension Array where Element: CerealType {
func serialize(to filePath: String) throws {
var encoder = CerealEncoder(capacity: self.count)
try encoder.encode(self, forKey: "array")
let data = encoder.toData()
@Sega-Zero
Sega-Zero / export_xliff.command
Created January 6, 2016 20:43
An alternative for run_genstrings script. Uses xliff export and import. Replace {YourProjectNameHere} with your project file name. Script expects to be located in the project's root directory.
cd "`dirname "$0"`"
#this will export ru.xliff file into LocalizedFiles subfolder
xcodebuild -exportLocalizations -project ./{YourProjectNameHere}.xcodeproj -localizationPath LocalizedFiles -exportLanguage ru
#I prefer to edit xml files in TextWrangler, replace it with TextEdit, or any other text editor you like
echo `open -a 'TextWrangler' ./LocalizedFiles/ru.xliff`
@Sega-Zero
Sega-Zero / run_genstrings.command
Last active January 6, 2016 18:44
A useful bash script to gather all localizable strings of your Objective-C project into Localizable.strings file with UTF8 encoding. The script should be placed to the root of your project. Replace {ProjectFolderName} with your project's folder path and you're done!
cd "`dirname "$0"`/{ProjectFolderName}"
find . -name "*.m" -print0 | xargs -0 genstrings -o Base.lproj
cd ./Base.lproj
#this is to encode Localizable.strings in UTF8 encoding
iconv -f UTF-16 -t UTF-8 Localizable.strings > Localizable.strings1
rm -f Localizable.strings
mv Localizable.strings1 Localizable.strings
@Sega-Zero
Sega-Zero / addDependency.m
Last active August 29, 2015 14:23
an example of NSOperation addDependency for this SO question: http://stackoverflow.com/q/30851799/1254172
//assume NSOperationQueue *operationQueue is created somewhere
//assume dispatch_semaphore_t semaphore is created somewhere
NSOperation *firstOperation = [NSBlockOperation blockOperationWithBlock:^{
[self doTask1];
}];
NSOperation *secondOperation = [NSBlockOperation blockOperationWithBlock:^{
[self doTask2];
}];
NSOperation *notificationOperation = [NSBlockOperation blockOperationWithBlock:^{