Replacing character in string with Swift

It may look like a little thing that may not even worth to write on my blog but this little stuff just saved me tons of time and a huge panic attack while i was working on coding some http requests for a iPhone app. So here it is:

var newsParam = "Aston Martin"
var convertedNewsParam = newsParam.stringByReplacingOccurrencesOfString(" ", withString: "%20")
var webservicePath = "http://xx.xx.xx.xx:yy/myWebService?search_text=\(convertedNewsParam)"

Some may say, “Why don’t you request by using id?”. That’s what i said my colleagues but their code was working this way and they didn’t want to change it since it’s working. So, when i just copy-pasted url to Postman with request parameter as “Aston Martin” it was working fine but it was giving me this error message: fatal error: unexpectedly found nil while unwrapping an Optional value

But when i changed space charater to it’s html equivalent (which is “%20” as you see from the code) and change my request parameter to Aston%20Martin it sets us free from that fatal error.

Yorum bırakın

Filed under Swift

How to change language on Adobe CC to english? (On Mac)

*note: i tested this only on Photoshop

Just follow these steps:

  1. Close Photoshop or whatever you’ve opened
  2. Go to Finder > Preferences and check first checkbox (Show all filename extensions) and close the window
  3. Go to Finder > File > New File Window then select Applications
  4. Go to Adobe Photoshop CC > Locales > tr_TR > Support Files
  5. Rename the extension of .dat file to .bak

That should do the trick. Now when you opened your photoshop, it should be using English language

Yorum bırakın

Filed under Adobe

How to Load UIViewController programmatically with Swift?

Sometimes you may have to display a view with an element that you cannot or should not create an outlet with it. In that occasions, this is what you need:

let vc : AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("myTargetViewController")

self.showViewController(vc as UIViewController, sender: vc)

But in order to make this thing work; Open your storyboard, display Identity Inspector at right pan of your Xcode and copy “myTargetViewController” to that view controller’s Storyboard ID. That should do the trick ;)

Yorum bırakın

Filed under Swift

How to Write to NTFS Drives in OS X

First of all, chmod is not the answer.

  1. sudo nano /etc/fstab
  2. Write “LABEL=drivename none ntfs rw,auto,nobrowse” in fstab
  3. kntrl-O & kntrl-X shotcuts will write and save your changes
  4. Unmount your drive from Mac
  5. Unplug your drive from Mac
  6. Plug your drive back in
  7. Within Finder’s menu bar, click “Go to Folder”
  8. Type /Volumes in “Go to Folder” screen. This will display all drives whether they’re available or not
  9. Drag your drive into Favourites, left of current Finder screen.

This is how you do it.

Yorum bırakın

Filed under Mac OS X

Cannot start PyCharm No JDK found

If have an error message like “ERROR: Cannot start PyCharm No JDK found. Please validate either PYCHARM_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.” while trying to install pycharm on ubuntu, this how you fix it:

 sudo apt-get purge openjdk*
 sudo add-apt-repository ppa:webupd8team/java
 sudo apt-get update
 sudo apt-get install oracle-java7-installer

Yorum bırakın

Filed under Python, Ubuntu

How to Run Bash Scripts within Python?

There are 2 different approaches:

import os
os.system('echo "hello"')

import subprocess"./", shell=True)

Some say first approach is deprecated but i think they haven’t faced any problem when all you need is a single line command to run within different parameters. So, in my opinion each one has it’s own advantage.

Yorum bırakın

Filed under Python

How to split text files into small subsets with Python?

This is how you do it:

lines_per_file = 500
smallfile = None
with open('processedTotal.txt') as bigfile:
   for lineno, line in enumerate(bigfile):
      if lineno % lines_per_file == 0:
         if smallfile:
         small_filename = 'set_{}.txt'.format(lineno + lines_per_file)
         smallfile = open(small_filename, "w")
   if smallfile:

Yorum bırakın

Filed under Python

SCP (Secure Copy) through SSH

Copying file/folder to host:

scp SourceFile user@host:directory/TargetFile
scp -r /local/folder/directory/ user@host:/target/folder/directory

Copying file/folder from host:

scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder

Note that if the remote host uses a port other than the default of 22, it can be specified in the command. For example, copying a file from host:

scp -P 2222 user@host:directory/SourceFile TargetFile

Yorum bırakın

Filed under Linux, Mac OS X

How to log all input/output in a terminal session?

Start logger : script myTerminalSession.log

Stop logger : exit

Yorum bırakın

Filed under Ubuntu

How to delete all indexed data on Apache Solr?

curl http://localhost:8983/solr/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8'

curl http://localhost:8983/solr/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8'

Yorum bırakın

Filed under Solr