{"id":1517,"date":"2012-11-10T00:18:20","date_gmt":"2012-11-09T23:18:20","guid":{"rendered":"http:\/\/www.thetawelle.de\/?page_id=1517"},"modified":"2019-12-23T00:22:00","modified_gmt":"2019-12-22T23:22:00","slug":"code-snippets","status":"publish","type":"page","link":"https:\/\/www.thetawelle.de\/?page_id=1517","title":{"rendered":"Code Snippets"},"content":{"rendered":"<p>Einige gesammelte Code Schnipsel und Codezeilen z.B. Shell-Scripte, Objective-C, oder \u00c4hnliches. <\/p>\n<h3>Shell: Reset des USB-Subsystems<\/h3>\n<p>Ist mir pers\u00f6nlich jetzt schon mehrfach passiert, das das USB-Subsystem nicht mehr funktioniert hat. Sprich, bestimmte Festplatten wurden nicht mehr registriert beim einstecken oder bestimmte Smartphones. Man kann jedoch im Betrieb das USB zur\u00fccksetzen. Ein wenig Vorsicht ist aber geboten&#8230; denn die Tastatur und Maus h\u00e4ngt auch am USB wie der <a href=\"http:\/\/teilweise.tumblr.com\/post\/62701229825\">Teilweise<\/a> berichtet. Wenn man das also runterf\u00e4hrt kann man seine Maschine nicht mehr steuern.<\/p>\n<p>Man kann dennoch einfach die USB-Kernelextension ausknipsen und wieder an. Am besten startet man das Anschalten automatisch nach paar Sekunden, dann muss man sich nicht m\u00fchevoll auf die eigene Kiste einloggen. Ich hab die Codezeilen vom <strong>Teilweise<\/strong> mal etwas gepimp&#8217;ed. (bash-Script als <a href=\"\/wp-upload\/restartSubsystemUsb.txt\">restartSubsystemUsb.txt<\/a> laden).<\/p>\n<pre class=\"brush: bash; gutter: false; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n#!\/bin\/sh\r\n#\r\n# Script to restart the USB subsystem by unloading and reloading the\r\n# USB kernel extension which drives the USB system components.\r\n# This is useful if you have unresponding USB ports or devices\r\n# which are no longer correctly registered in the USB system\r\n# after some weird errors happened and you don't feel like restating\r\n# your whole machine just for this to be fixed.\r\n#\r\nif (( $EUID != 0 )); then\r\n\techo &quot;PLEASE RUN AS ROOT.&quot;\r\n\texit\r\nfi\r\n\r\necho &quot;&quot;\r\necho &quot;RESTARTING USB SUBSYSTEM NOW...&quot;\r\nsleep 2\r\necho &quot;SHUTDOWN...&quot;\r\nsleep 2\r\n# shutting down here\r\necho &quot;TIME: `date`&quot;\r\nkextunload -b com.apple.driver.AppleUSBEHCI\r\necho &quot;TIME: `date`&quot;\r\necho &quot;WAITING 20 SECONDS...&quot;\r\nsleep 20\r\necho &quot;RESTART...&quot;\r\n# rebooting here\r\necho &quot;TIME: `date`&quot;\r\nkextload -b com.apple.driver.AppleUSBEHCI\r\necho &quot;TIME: `date`&quot;\r\necho &quot;DONE&quot;\r\necho &quot;&quot;\r\n<\/pre>\n<p>Man bekommt dann ungef\u00e4hr sowas hier als Output, w\u00e4hrend alle Ger\u00e4te, auch die Bluetoothger\u00e4te (wie Trackpad) kurzzeitig ihre Verbindung verlieren.<\/p>\n<p><code><br \/>\nRESTARTING USB SUBSYSTEM NOW...<br \/>\nSHUTDOWN...<br \/>\nTIME: Di 16 Sep 2014 10:52:19 CEST<br \/>\n(kernel) Can't unload kext com.apple.driver.AppleUSBEHCI; classes have instances:<br \/>\n(kernel)     Kext com.apple.driver.AppleUSBEHCI class AppleEHCIIsochTransferDescriptor has 168 instances.<br \/>\n(kernel)     Kext com.apple.driver.AppleUSBEHCI class AppleEHCIIsochEndpoint has 5 instances.<br \/>\nFailed to unload com.apple.driver.AppleUSBEHCI - (libkern\/kext) kext is in use or retained (cannot unload).<br \/>\nTIME: Di 16 Sep 2014 10:52:20 CEST<br \/>\nWAITING 20 SECONDS...<br \/>\nRESTART...<br \/>\nTIME: Di 16 Sep 2014 10:52:40 CEST<br \/>\nTIME: Di 16 Sep 2014 10:52:40 CEST<br \/>\nDONE<br \/>\n<\/code><\/p>\n<h3>Objective-C: iOS 7\/iOS 8 Transition von iOS 6<\/h3>\n<p>Th <u><strong>best<\/strong><\/u> 2 lines of code for the transition you will ever find:<\/p>\n<pre class=\"brush: cpp; gutter: false; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nmyViewController.edgesForExtendedLayout = UIRectEdgeNone;\r\nrootNavigationController.navigationBar.translucent = NO;\r\nrootNavigationController.toolbar.translucent = NO;\r\n<\/pre>\n<h3>Shell: Inkompatibilit\u00e4ten von Steuercodes f\u00fcr Cursortasten in vi abstellen<\/h3>\n<p>Wenn man sich per ssh auf andere Machinen einloggt, und per vi doch mal was editieren will, hat man oftmals das Problem, dass die Steuersequenzbelegung der Cursortasten von der eigene Emulation mal wieder nicht kompatibel ist. Folge ist z.B. bei vi gerne mal, dass man im edit-mode bei Nutzung der Cursortasten dann A, B, C, D erzeugt und der Cursor wegspringt. Auch das L\u00f6schen mit Backspace funktioniert nicht richtig. Das kann man schnell beheben indem man im vi zuerst eingibt:<\/p>\n<pre class=\"brush: bash; gutter: false; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n:set nocompatible\r\n<\/pre>\n<p>Oder aber man legt folgende Konfigurationsdatei f\u00fcr vi\/vim im $HOME an:<\/p>\n<pre class=\"brush: bash; gutter: false; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n.vimrc\r\n<\/pre>\n<p>mit dem folgenden Inhalt (man beachte wie \u00e4hnlich das zur Eingabe im vi ist):<\/p>\n<pre class=\"brush: bash; gutter: false; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nset nocompatible\r\n<\/pre>\n<p>Das setzt einen Parameter bei jedem Start von vi. So wird das problem jedoch nur f\u00fcr den vi gel\u00f6st. Andere Kommandozeilentools leiden weiterhin. Deshalb alternativ kann man auch in dem eigenen Terminal Programm mal <a href=\"http:\/\/foohack.com\/2007\/09\/fix-for-vis-broken-arrow-key-support-in-iterm\/\">in den Settings w\u00fchlen<\/a> und die default-Emulation mal \u00e4ndern (da stehen oft so Sachen wie xterm-color16, ansi, vt100, linus, usw.). Sofern &#8222;linux&#8220; verf\u00fcgbar ist sollte man das mal nehmen. Wird aber meist erst aktiv nach einem Neustart des eingesetzten Terminal Programms.<\/p>\n<h3>Shell: Text to PDF von der Kommandozeile<\/h3>\n<p>Hiermit kann man von der Kommandozeile aus normalen Text in sch\u00f6n formatiertes PDF umleiten, mittels <code>enscript<\/code>, das man widerum per <code>MacPorts<\/code> installieren kann.<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n#!\/bin\/bash\r\n\r\nMOD_TIME_EPOCH=`stat -f %m $1`\r\nMOD_TIME_FMT=`date -r $MOD_TIME_EPOCH +'%a %e %b %Y @ %R %Z' | sed 's\/ &#x5B; ]*\/ \/g'`\r\nFULL_NAME=`php -r &quot;echo realpath('$1');&quot;`\r\n\r\nmkdir -p $HOME\/.enscript\r\n\r\n# Create temporary &quot;fancy header&quot; file for enscript.\r\ncat &gt; $HOME\/.enscript\/tmp_txt2pdf.hdr &lt;&lt;EOF\r\n% -- code follows this line --\r\n%Format: last_mod_timestr $MOD_TIME_FMT\r\n%Format: pagestr page \\$V$%\/$=\r\n%HeaderHeight: 30\r\n%FooterHeight: 30\r\n\/Helvetica \/helvetica-encoded MF\r\n\/Helvetica-10-Regular \/helvetica-encoded findfont 10 scalefont def\r\n\/Helvetica-Bold \/helvetica-bold-encoded MF\r\n\/Helvetica-10-Bold   \/helvetica-bold-encoded findfont 10 scalefont def\r\n\/new_marg 4 def\r\n\/do_header {\r\n  gsave\r\n    Helvetica-10-Bold setfont\r\n    d_footer_x d_footer_w add pagestr stringwidth pop sub\r\n    new_marg sub\r\n    d_footer_y 7 add moveto pagestr show\r\n    Helvetica-10-Bold setfont\r\n    d_footer_x new_marg add d_footer_y 7 add moveto last_mod_timestr show\r\n    Helvetica-10-Bold setfont\r\n    d_header_x d_header_w 2 div add fname stringwidth pop 2 div sub\r\n    d_header_y 16 add moveto fname show\r\n  grestore\r\n} def\r\nEOF\r\n\r\nenscript --encoding=latin1 --fancy-header=tmp_txt2pdf --word-wrap -p - &quot;$FULL_NAME&quot; | gs -q \\\r\n    -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=&quot;$2&quot; -\r\n\r\nrm -f $HOME\/.enscript\/tmp_txt2pdf.hdr\r\n<\/pre>\n<h3>Shell: Lang laufende UNIX jobs mit Benachrichtigung<\/h3>\n<p>Folgende Codezeile hilft einem, das Ende eines Jobs nicht zu verpassen. Sobald der Task beendet wurde wird mittels <code>tput bel<\/code> eine akustische Meldung ausgegeben und ein roter Badge an das Terminalicon im Dock gepackt.<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nmake install &amp;&amp; tput bel\r\n<\/pre>\n<p>Es geht auch noch eleganter, wenn man sich mittels des Ruby GEMS <code>terminal-notifier<\/code> (bei <a href=\"https:\/\/github.com\/alloy\/terminal-notifier\">GitHUB<\/a>) im Message Center von OS X benachrichtigen lassen will.<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nterminal-notifier -message &quot;Installation vom Terminal ist fertig!&quot; -title &quot;Terminal hat feddich!&quot;\r\n<\/pre>\n<h3>Shell: FileSharing &#038; FTP-Server von der Konsole aus starten &#038; stoppen<\/h3>\n<p>Grade wenn man mehrere Macs im Haus hat (z.B. auch als MediaServer), ist das folgende Kommando ganz praktisch, wenn man sich per SSH auf die Zielmaschine einklinken kann und dann ohne viel Aufwand mal eben FileSharing anknippsen kann. So muss man keinen Bildschirm anschlie\u00dfen und das Einstellungspanel f\u00fcr Sharing-Dienste anklicken.<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n# Zum Starten des FileSharing\r\nlaunchctl load -w \/System\/Library\/LaunchDaemons\/com.apple.AppleFileServer.plist\r\n# Zum Stoppen des FileSharing\r\nlaunchctl unload -w \/System\/Library\/LaunchDaemons\/com.apple.AppleFileServer.plist\r\n<\/pre>\n<p>Auf die gleiche Art kann man sich \u00fcbrigens einen FTP-Serverdienst an- und ausschalten.<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n# Zum Starten des FTP-Server\r\nlaunchctl load -w \/System\/Library\/LaunchDaemons\/ftp.plist\r\n# Zum Stoppen des FTP-Server\r\nlaunchctl unload -w \/System\/Library\/LaunchDaemons\/ftp.plist\r\n<\/pre>\n<h3>Objective-C: Richtiges escapen von values f\u00fcr URL-Parameter<\/h3>\n<p>Leider ist die Methode von NSString <code>stringByAddingPercentEscapesUsingEncoding<\/code> nicht wirklich brauchbar f\u00fcr das escapen von Zeichen wie z.B. dem <code>&amp;,?,#<\/code> usw. daher nutze ich folgende Methoden f\u00fcr diese Arbeit.<\/p>\n<pre class=\"brush: cpp; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n\/\/ String encoden f\u00fcr Verwendung in URL als value\r\nNSString* newEncodeToPercentEscapeString(NSString *string) {\r\n    return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) string,NULL,(CFStringRef) @&quot;!*'();:@&amp;=+$,\/?%#&#x5B;]&quot;,kCFStringEncodingUTF8);\r\n}\r\n\r\n\/\/ String decoden\r\nNSString* newDecodeFromPercentEscapeString(NSString *string) {\r\n    return (NSString *) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,(CFStringRef) string, CFSTR(&quot;&quot;), kCFStringEncodingUTF8);\r\n}\r\n<\/pre>\n<p>Aber Achtung der String kommt mit retaincount=1 zur\u00fcck&#8230; man muss den also releasen wenn man fertig ist.<\/p>\n<h3>Objective-C: Autolayout im \u00dcbergang iOS 5 zu iOS 6<\/h3>\n<p>Apple hat mit iOS 6 eine ganze Menge ver\u00e4ndert hinsichtlich der bisherigen Layoutfunktionen. U.a. damit sie die neue Displaygr\u00f6\u00dfe des iPhone 5 abbilden k\u00f6nnen. Nervig ist allerdings, dass man w\u00e4hrend des \u00dcbergangs nun f\u00fcr die ganz normale AutoRotation statt wie bisher einer jetzt bis zu f\u00fcnf Methoden einbauen muss damit sich was dreht. N\u00e4mlich folgende:<\/p>\n<pre class=\"brush: cpp; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n\/**\r\n * Im AppDelegate\r\n *\/\r\n\r\n\/\/ NEWER IOS &gt;= 6.x\r\n- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {\r\n    return UIInterfaceOrientationMaskAll;\r\n}\r\n\r\n\/**\r\n * Im ViewController\r\n *\/\r\n\r\n\/\/ OLDER IOS &lt; 6.x\r\n- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {\r\n    return YES;\r\n}\r\n\r\n\/\/ NEWER IOS &gt;= 6.x\r\n- (BOOL) shouldAutorotate {\r\n    return YES;\r\n}\r\n\r\n\/\/ NEWER IOS &gt;= 6.x\r\n- (NSUInteger)supportedInterfaceOrientations {\r\n    return UIInterfaceOrientationMaskAll;\r\n}\r\n\r\n\/\/ NEWER IOS &gt;= 6.x (OPTIONAL)\r\n- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {\r\n    return UIInterfaceOrientationPortrait;\r\n}\r\n<\/pre>\n<p>Tja, da hat man grade das bisherige Layout-System in den Griff bekommen, \u00e4ndert sich mal wieder alles.<\/p>\n<h3>L\u00e4stige Warnings im Code von anderen<\/h3>\n<p>Gerade wer die Regel verfolgt, &#8222;Warnings = Errors&#8220;, der \u00e4rgert sich \u00fcber unsauberen Code anderer. Aber in der realit\u00e4t kann man nicht jede Codezeile von anderen fixen, bloss weil da ne Warning hochkommt. Daher kann man sich elegant dieser Warnings wie folgt entledigen, z.B. wenn man wei\u00df das der Code so in Ordnung ist. Man schaltet kurzzeitig die Compilerdiagnostik aus (PUSH einer neuen Regel) f\u00fcr die entsprechenden Warnungen und danach wieder ein (POP der hinzugef\u00fcgten Diagnoseregel).<\/p>\n<pre class=\"brush: cpp; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n\/\/ NEUE DIAGNOSEREGEL PUSHEN\r\n#pragma clang diagnostic push\r\n#pragma clang diagnostic ignored &quot;-Wformat-nonliteral&quot;\r\n- (void)logMessage:(NSString *)format\r\n         level:(LoggingLevel)level withParameters:(va_list)valist {\r\n         if (level &gt;= self.loggingLevel) {\r\n              NSString *formattedString = &#x5B;&#x5B;NSString alloc] initWithFormat:format arguments:valist];        \r\n         } \r\n\/\/ HINZUGEF\u00dcGTE DIAGNOSEREGEL ENTFERNEN\r\n#pragma clang diagnostic pop\r\n<\/pre>\n<p>Einfach, oder? Und hilft auch bei anderen Diagnosealarmen die eher zu den <strong>false positives<\/strong> gez\u00e4hlt werden d\u00fcrfen.<\/p>\n<h3>Objective-C: Ein DEBUG-flag, das nicht mehr von Xcode bestimmt\/gehijacked wird<\/h3>\n<p>Xcode setzt von Haus aus gerne bei einem Development Build das DEBUG flag in den PRECOMPILER STATEMENTS auf TRUE, jedenfalls seit einer Weile schon. Ich beziehe bich \u00f6fters auf dieses Flag, um bestimmten Code und bestimmte Code-Bestandteile nur dann auszuf\u00fchren, wenn die App in Entwicklung ist. Doch ab und an h\u00e4tte ich ja gerne auch mal einen RUN mit DEBUG = FALSE auch wenn ich einen Development Build fahre. Daf\u00fcr m\u00fcsste ich jetzt normalerweise in den Einstellungsscreens (diese Excel-Tabellen-m\u00e4\u00dfige Parameter-W\u00fcste) das DEBUG Zeug deaktivieren. Schneller und einfacher gehts, wenn man ein eigenes DEBUG flag hat, bei dem man wei\u00df, dass da keiner dran rumdreht auch Xcode nicht. Ich meinen precompiler header files (.pch) mache ich daher oft das Folgende:<\/p>\n<pre class=\"brush: cpp; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n\/\/ SETUP OWN DEBUG FLAG\r\n#define DEBUG_MASTER 1\r\n\r\n\/\/ SETUP DEBUG FLAG DEFINED BY XCODE\r\n#ifndef DEBUG\r\n#define DEBUG DEBUG_MASTER\r\n#else\r\n#undef DEBUG\r\n#define DEBUG DEBUG_MASTER\r\n#endif\r\n<\/pre>\n<p>Wenn man n\u00e4mlich einfach das DEBUG von Xcode nochmal definiert hilft das nicht und es gibt eine warning. Daher definiere ich das optional weg und definiere es mit meinem MASTER_DEBUG flagzustand neu. Funktioniert zuverl\u00e4ssig!<\/p>\n<h3> How Do I Declare A Block in Objective-C?<\/h3>\n<p>The following text was copied from a webpage (see footer\/source note) because it is really useful for those damn block statements &#8218;ya know?<\/p>\n<style type=\"text\/css\">\n.headline {color:#0088D9;}\n.return { color:#00A69A; }\n.name {color:#BC8800; }\n.parameter-types, .parameters {color:#7C9F00;}\n.rounded-corners {\n     -moz-border-radius: 7px;\n    -webkit-border-radius: 7px;\n    -khtml-border-radius: 7px;\n    border-radius: 7px;\n}\n    footer {\n      font-size: 12px;\n      margin-top: 200px;\n      opacity: 0.4;\n      text-align: right;\n    }<\/p>\n<p>    footer a {\n      color: #0088D9;\n      text-decoration: none;\n    }<\/p>\n<\/style>\n<div style=\"background-color:#042029;color:#83948F;font-family:Lucida Grande,sans-serif;padding:10px;margin-top:10px;\" class=\"rounded-corners\">\n<div>\n<h3 class=\"headline\">As an <span class=\"headline\">instance variable<\/span>:<\/h3>\n<p>    <code><br \/>\n      <span class=\"return\">returnType<\/span> (^<span class=\"name\">blockName<\/span>)(<span class=\"parameter-types\">parameterTypes<\/span>) = ^<span class=\"return\">returnType<\/span>(<span class=\"parameters\">parameters<\/span>) {...};<br \/>\n    <\/code>\n  <\/div>\n<div>\n<h3 class=\"headline\">As a <span class=\"headline\">property<\/span>:<\/h3>\n<p>    <code><br \/>\n      @property (nonatomic, copy) <span class=\"return\">returnType<\/span> (^<span class=\"name\">blockName<\/span>)(<span class=\"parameter-types\">parameterTypes<\/span>);<br \/>\n    <\/code>\n  <\/div>\n<div>\n<h3 class=\"headline\">As a <span class=\"headline\">method parameter<\/span>:<\/h3>\n<p>    <code><br \/>\n      - (void)someMethodThatTakesABlock:(<span class=\"return\">returnType<\/span> (^)(<span class=\"parameter-types\">parameterTypes<\/span>))<span class=\"name\">blockName<\/span> {...}<br \/>\n    <\/code>\n  <\/div>\n<div>\n<h3 class=\"headline\">As an <span class=\"headline\">argument to a method call<\/span>:<\/h3>\n<p>    <code><br \/>\n      [someObject someMethodThatTakesABlock: ^<span class=\"return\">returnType<\/span> (<span class=\"parameters\">parameters<\/span>) {...}];<br \/>\n    <\/code>\n  <\/div>\n<div>\n<h3 class=\"headline\">As a <span class=\"headline\">typedef<\/span>:<\/h3>\n<p>    <code><br \/>\n      typedef <span class=\"return\">returnType<\/span> (^<span class=\"name\">TypeName<\/span>)(<span class=\"parameter-types\">parameterTypes<\/span>);<br \/>\n      <span class=\"name\">TypeName<\/span> blockName = ^(<span class=\"parameters\">parameters<\/span>) {...}<br \/>\n    <\/code>\n  <\/div>\n<footer>By <a href=\"http:\/\/lazerwalker.com\">Mike Walker<\/a>, who has a very bad memory for this sort of thing.<br \/>Source: <a href=\"http:\/\/fuckingblocksyntax.com\/\">http:\/\/fuckingblocksyntax.com<\/a><\/footer>\n<\/div>\n<h3>Objective-C: Override system locale to have custom app locale at any time<\/h3>\n<p>I just want to share a trick on how to <strong>gain control over the Locale<\/strong> used for your app. The following code snippet is put in the main-method which kicks of your app.<\/p>\n<p>But basically you should call this code snippet in your app and then make the user quit\/terminate the app afterwards to restart with the new set default language AND set these parameters here again depending on a flag you may have stored elsewhere. Because actually all those set default values are actually already used at an earlier point in time i.e. for date formatting.<\/p>\n<pre class=\"brush: cpp; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nint main(int argc, char *argv&#x5B;])\r\n{\r\n    @autoreleasepool {\r\n        \r\n        \/\/ OVERRIDE LOCALE (BASICALLY DO THIS WHILE APP RUNS AND LET USER RESTART APP)\r\n        BOOL shouldOverrideLocale = NO; \/\/ LET'S TRY TO OVERRIDE IT WITH en_US\r\n        NSString *languageIdentifier = @&quot;en&quot;;\r\n        NSString *countryIdentifier = @&quot;US&quot;;\r\n        NSUserDefaults *defaults = &#x5B;NSUserDefaults standardUserDefaults];\r\n        \r\n        if( shouldOverrideLocale ) {\r\n            NSLog( @&quot;OVERRIDING SYSTEM LOCALE WITH : %@_%@&quot;,languageIdentifier, countryIdentifier );\r\n            &#x5B;defaults setObject:&#x5B;NSArray arrayWithObject:languageIdentifier] forKey:@&quot;AppleLanguages&quot;];\r\n            &#x5B;defaults setObject:&#x5B;NSArray arrayWithObjects:languageIdentifier, nil] forKey:@&quot;NSLanguages&quot;];\r\n            &#x5B;defaults setObject:&#x5B;NSString stringWithFormat:@&quot;%@_%@&quot;, languageIdentifier, countryIdentifier] forKey:@&quot;AppleLocale&quot;];\r\n            &#x5B;defaults synchronize];\r\n        }\r\n        else {\r\n            NSArray *keysToRemove = @&#x5B;@&quot;AppleLanguages&quot;,@&quot;NSLanguages&quot;,@&quot;AppleLocale&quot;];\r\n            NSLog( @&quot;RESETTING TO USE SYSTEM LOCALE&quot; );\r\n            @try {\r\n                for( NSString *currentKey in keysToRemove ) {\r\n                    if( &#x5B;defaults objectForKey:currentKey] ) {\r\n                        &#x5B;defaults removeObjectForKey:currentKey];\r\n                    }\r\n                }\r\n            }\r\n\t        @catch (NSException *exception) {\r\n\t            \/\/ NOTHNG TO CATCH HERE\r\n\t        }\r\n\t        @finally {\r\n\t\t\t\t&#x5B;defaults synchronize];\r\n\t        }\r\n        }\r\n        NSString *languageCode = &#x5B;&#x5B;NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleLanguageCode];\r\n        NSString *countryCode = &#x5B;&#x5B;NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleCountryCode];\r\n        NSLog( @&quot;USING SYSTEM LOCALE: %@_%@&quot;, languageCode, countryCode );\r\n\r\n        return UIApplicationMain(argc, argv, nil, NSStringFromClass(&#x5B;AppDelegate class]));\r\n    }\r\n}\r\n<\/pre>\n<p>If you use this code, keep in mind, that strings and processes related to In-App-Purchase are still delivered in the native language of the user.<\/p>\n<h3>How to revert pngcrushed aka optimized PNG files in iOS<\/h3>\n<p>Xcode does optimized PNG&#8217;s when running them through the build system. It makes them non-standard and uneditable by even Photoshop. To restore an image from the assets bundled in your app, you need to revert the optimization process or at least make it a valid PNG again. This is how&#8230;<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\n\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/usr\/bin\/pngcrush -revert-iphone-optimizations -q optimized.png reverted.png\r\n<\/pre>\n<h3>How to export all Apple Keychain Certificates as a .pem file (which format does not matter)<\/h3>\n<p>If you have an old Mac which does not get supported any more with updates, you end up having a lot of invalid root certificates in your System keychain. Since several applications like e.g. the Safari Browser use these certs to check authenticity of TLS-secured websites, you need valid ones. Simplest way is to export all those certificates from an up-to-date Mac machine and import those on the legacy machine. The <strong>security<\/strong> command helps here. With <code>security list-keychains<\/code> you get a list of the relevant Keychains. You can access them also vie the GUI tool. The issue with the GUI tool is&#8230; it cannot export more than 1 certificate in one action. The GUI sucks a lot! Just use following command&#8230;<\/p>\n<pre class=\"brush: bash; gutter: true; title: Source\/Snippet; toolbar: true; notranslate\" title=\"Source\/Snippet\">\r\nsecurity export -k \/Library\/Keychains\/System.keychain -t certs -o \/Users\/jollyjinx\/Xserve\/CertsFromSystemKeychain.pem\r\n<\/pre>\n<p>When successfulle exportet the <code>.pem-<\/code>File contains <strong>ALL<\/strong> certificates. On the target machine just double-click on the pem-File and Keychain will offer you to import all of them. Some will fail for weird reasons beyond my understanding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Einige gesammelte Code Schnipsel und Codezeilen z.B. Shell-Scripte, Objective-C, oder \u00c4hnliches. Shell: Reset des USB-Subsystems Ist mir pers\u00f6nlich jetzt schon mehrfach passiert, das das USB-Subsystem nicht mehr funktioniert hat. Sprich, bestimmte Festplatten wurden nicht mehr registriert beim einstecken oder bestimmte Smartphones. Man kann jedoch im Betrieb das USB zur\u00fccksetzen. Ein wenig Vorsicht ist aber geboten&#8230; &hellip; <a href=\"https:\/\/www.thetawelle.de\/?page_id=1517\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eCode Snippets\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":8,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-1517","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=\/wp\/v2\/pages\/1517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1517"}],"version-history":[{"count":0,"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=\/wp\/v2\/pages\/1517\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.thetawelle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}