Analyzing string input until it reaches a certain letter on Python

The built-in str.partition() method will do this for you. Unlike str.split() it won’t bother to cut the rest of the str into different strs. text = raw_input(“Type something:”) left_text = text.partition(“!”)[0] Explanation str.partition() returns a 3-tuple containing the beginning, separator, and end of the string. The [0] gets the first item which is all you … Read more

How does one store history of edits effectively?

There are a number of options, the simplest, of course, being to simply record all versions independently. For a site like Stack Overflow, where posts aren’t usually edited very many times, this is appropriate. However for something like Wikipedia, one needs to be more clever to save space. In the case of Wikipedia, pages are … Read more

Github gist editing without changing URL

Gist changed the path to this file pattern: https://gist.github.com/<USER_NAME>/<GIST_ID>/raw/<GIST_REVISION_ID>/<GIST_FILE_NAME> You will notice that now the top answers’ links are 404’ing. Simply apply this new pattern and voilĂ ! https://gist.github.com/<USER_NAME>/<GIST_ID>/raw/<GIST_FILE_NAME> For instance: https://gist.githubusercontent.com/wesbos/cd16b8b1815825f111a2/raw/lol.js

Cannot edit checked out file (TFS) in Visual Studio 2013

I suspended Resharper and restarted Visual Studio 2013. Once I reopened it the problem was gone. Resuming Resharper caused the problem to emerge again. The solution is quite large so maybe that is it. Before putting Resharper into suspend mode I tried switching off code analysis thinking the workload is just too great, but that … Read more

Edit In Place Content Editing

You should put the form inside each node and use ng-show and ng-hide to enable and disable editing, respectively. Something like this: <li> <span ng-hide=”editing” ng-click=”editing = true”>{{bday.name}} | {{bday.date}}</span> <form ng-show=”editing” ng-submit=”editing = false”> <label>Name:</label> <input type=”text” ng-model=”bday.name” placeholder=”Name” ng-required/> <label>Date:</label> <input type=”date” ng-model=”bday.date” placeholder=”Date” ng-required/> <br/> <button class=”btn” type=”submit”>Save</button> </form> </li> The key … Read more

Android: Edit Text Go Button

You want a combination of android:imeOptions and setOnEditorActionListener <EditText android:id=”@+id/some_edittext” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:imeOptions=”actionSend”> </EditText> some_edittext.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { some_button.performClick(); return true; } return false; } }); Obviously you should change actionSend to the action you want, and update IME_ACTION_SEND correspondingly.

Edit Distance in Python

The thing you are looking at is called an edit distance and here is a nice explanation on wiki. There are a lot of ways how to define a distance between the two words and the one that you want is called Levenshtein distance and here is a DP (dynamic programming) implementation in python. def … Read more