Skip to content

Instantly share code, notes, and snippets.

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

  • Nizhnekamsk
View GitHub Profile
Sega-Zero / TrainAnimationView.swift
Created Feb 16, 2020
View with waiting animation that seems like a train on a railroad
View TrainAnimationView.swift
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 / TestSample.swift
Last active May 1, 2016
Example structures for stress-testing a Cereal library
View TestSample.swift
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 /
Created Jan 8, 2016
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
#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 / export_xliff.command
Created Jan 6, 2016
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.
View export_xliff.command
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 / run_genstrings.command
Last active Jan 6, 2016
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!
View run_genstrings.command
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 / addDependency.m
Last active Aug 29, 2015
an example of NSOperation addDependency for this SO question:
View addDependency.m
//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:^{
You can’t perform that action at this time.