Skip to content

Instantly share code, notes, and snippets.

View cbess's full-sized avatar
💭
Coding for Jesus' glory. Soli Deo gloria

C. Bess cbess

💭
Coding for Jesus' glory. Soli Deo gloria
View GitHub Profile
@cbess
cbess / django-schema_inspectdb-changes
Created June 17, 2011 16:00
django 1.3 postgresql schema (search path) fix for inspectdb and db connection
= Modify: django.core.management.commands.inspectdb
- line 33, add
- cursor.execute("SET search_path TO myschema")
- line 80, change to
- field_type = 'ForeignKey(\'%s\'' % rel_to
- now you can ignore the model ordering
= Modify: django.db.backends.postgres_psycopg2.base
- line 147, add
- cursor.execute("SET search_path TO myschema")
@cbess
cbess / macros.h
Created September 13, 2011 18:48
iOS UIView.frame.origin = rect macro
// Expands to set self.frame.origin
#define UIViewOrigin(X, Y) ({ \
CGRect frame = self.frame; \
frame.origin = CGPointMake(X, Y); \
self.frame = frame; })
@cbess
cbess / svn2gitpush.sh
Created September 26, 2011 00:04
Converts svn repo to git then pushes it to git remote repo
#!/bin/bash
# Created by Christopher Bess
# svn2git (https://github.com/nirvdrum/svn2git) helper script
# working directory (holds local git repos)
DIR=tmp
# the svn repo to convert
SVN_URL=https://svn.example.com/example
# the url to the git repo
GIT_URL=user@example.com:git/example.git
@cbess
cbess / function.m
Created October 3, 2011 15:11
Set UIView background image (the better way)
// Sets the view's background to the given image
static void SetBackgroundImage(UIView *view, NSString *imageName)
{
view.layer.contents = (id)[UIImage imageNamed:imageName].CGImage;
}
@cbess
cbess / gist:1393058
Created November 25, 2011 08:36
Set NSView layer background image
// Sets the view's background to the given image
// prior to call, you may need to execute: `view.wantsLayer = YES`
void SetBackgroundImage(NSView *view, NSString *imageName)
{
view.layer.contents = (id)[NSImage imageNamed:imageName];
}
@cbess
cbess / gist:1431627
Created December 4, 2011 23:21
Update Django model from dictionary
def update_model(model, save_update=True, **kwargs):
"""Updates the specified model instance using the keyword arguments as the model
property attributes and values.
Example usage:
update_model(mymodel, save_update=True, **some_dictionary)
"""
for attr, val in kwargs.items():
setattr(model, attr, val)
@cbess
cbess / gist:3049947
Created July 4, 2012 22:57
find by date error
/MyDrive/nodejs/node_modules/sqlite3/lib/trace.js:28
throw err;
^
TypeError: Cannot call method 'split' of undefined
at module.exports.QueryGenerator.hashToWhereConditions (/MyDrive/nodejs/node_modules/sequelize/lib/dialects/mysql/query-generator.js:263:29)
at _.map.results.length (/MyDrive/nodejs/node_modules/sequelize/node_modules/underscore/underscore.js:102:42)
at _.each._.forEach (/MyDrive/nodejs/node_modules/sequelize/node_modules/underscore/underscore.js:89:24)
at Function._.map (/MyDrive/nodejs/node_modules/sequelize/node_modules/underscore/underscore.js:101:5)
at Object.module.exports.QueryGenerator.hashToWhereConditions (/MyDrive/nodejs/node_modules/sequelize/lib/dialects/mysql/query-generator.js:249:22)
at Object.module.exports.QueryGenerator.getWhereConditions (/MyDrive/nodejs/node_modules/sequelize/lib/dialects/mysql/query-generator.js:237:33)
@cbess
cbess / gist:3049978
Last active October 6, 2015 20:38
Sequelize sample.
// get metric for the object id and today's date
var currentDate = new Date();
currentDate.setHours(0);
currentDate.setMinutes(0);
currentDate.setSeconds(0);
console.log(currentDate.toString());
StatMetric.find({
where : { object_id: metricObject.id, stat_type_id: statTypeId, current_date: currentDate}
});
@cbess
cbess / gist:4444374
Last active March 16, 2020 06:10
Xcode Delete and Duplicate Selected Lines
<key>Customized</key>
<dict>
<key>Delete Line</key>
<string>selectLine:, deleteBackward:</string>
<key>Duplicate Lines</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Duplicate Current Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>
@cbess
cbess / gist:4503317
Last active December 10, 2015 22:38
Animate ScrollView with custom duration
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.7f];
self.scrollView.contentOffset = CGPointMake(77, 77);
[UIView commitAnimations];