Skip to content

Instantly share code, notes, and snippets.

View joubertnel's full-sized avatar

Joubert Nel joubertnel

  • Netflix
  • Los Angeles, CA
View GitHub Profile
[self addObserver:[[poolView titleTextField] stringValue]
forKeyPath:"title"
options:CPKeyValueObservingOptionNew
context:nil];
+ (id)getWorkspaceList:(CPString)url for:(CPString)email withSecurity:(CPString)token
{
CPLogConsole("getWorkspaceList executing");
serviceURL = url + "/GetWorkspaceList&securityToken=" + token
+ "&email=" + email;
jsonData = [CPURLConnection sendSynchronousRequest:[CPURLRequest requestWithURL:serviceURL]
returningResponse:nil
error:nil];
CPLogConsole("serviceURL=" + serviceURL);
CPLogConsole("jsonData=" + jsonData);
@joubertnel
joubertnel / isort.py
Created November 5, 2010 21:23
Insertion sort in Python
def insertion_sort(keys):
index = 1
while index < len(keys):
key = keys[index]
comp_index = index - 1
while comp_index >= 0 and key < keys[comp_index]:
keys[comp_index], keys[comp_index+1] = keys[comp_index+1], keys[comp_index]
comp_index -= 1
index += 1
@joubertnel
joubertnel / merge_sort.py
Created November 8, 2010 23:45
Merge Sort
def merge(list1, list2):
result = []
index1 = index2 = 0
while index1 < len(list1) and index2 < len(list2):
key1 = list1[index1]
key2 = list2[index2]
if key1 <= key2:
result.append(key1)
index1 += 1
else:
@joubertnel
joubertnel / gist:668737
Created November 9, 2010 05:20
Create thumbnail of image
(defn make-thumbnail [in-stream out-stream width]
(let [img (javax.imageio.ImageIO/read in-stream)
imgtype (java.awt.image.BufferedImage/TYPE_INT_ARGB)
width (min (.getWidth img) width)
height (* (/ width (.getWidth img)) (.getHeight img))
simg (java.awt.image.BufferedImage. width height imgtype)
g (.createGraphics simg)]
(.drawImage g img 0 0 width height nil)
(.dispose g)
(javax.imageio.ImageIO/write simg "png" out-stream)))
@joubertnel
joubertnel / gist:859438
Created March 7, 2011 22:54
Diff of SC.BaseTheme.imageButtonRenderDelegate and the corresponding CSS file
diff --git a/themes/ace/resources/button/ace/button.css b/themes/ace/resources/button/ace/button.css
index 6934b86..4d3b2eb 100644
--- a/themes/ace/resources/button/ace/button.css
+++ b/themes/ace/resources/button/ace/button.css
@@ -26,3 +26,16 @@ $theme.button {
margin-top: 0px;
}
}
+
+
@joubertnel
joubertnel / gist:926613
Created April 19, 2011 00:56
API descriptor
{ baseUrl: 'http://www.myapi.com'
methods: [ { name: 'Get Users',
http: 'GET',
url: '/users',
result: { object: 'user'
array: 'true' }},
{ name: 'Create User',
http: 'POST',
url: '/users?name={name}&email={email}',
@joubertnel
joubertnel / gist:1264285
Created October 5, 2011 11:59
macros for faster NSArray and NSDictionary instancing
#define ARRAY(...) [NSArray arrayWithObjects:__VA_ARGS__, nil]
#define DICT(...) [NSDictionary dictionaryWithObjectsAndKeys:__VA_ARGS__, nil]
@joubertnel
joubertnel / gist:1289689
Created October 15, 2011 15:13
Dynamic state transition from sibling states in a SproutCore state chart
gotoStateFromFirstSiblingCurrentState: function(destinationState, commonParentState, defaultSourceState) {
var sourceState = this.get('currentStates').find(function(s) {
var isSibling = s.getPath('parentState.stateName') === commonParentState;
return isSibling;
});
sourceState = sourceState || defaultSourceState;
this.gotoState(destinationState, sourceState);
}
SC.routes.add(‘notes/:id’, function(routingArgs) {
MyApp.statechart.gotoState(’showTakeNotesView’, 'showBooksView’);
});