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 / position-cell.m
Last active August 29, 2015 13:56
Adjust the position of a UICollectionViewCell.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout*) self.collectionView.collectionViewLayout;
// CGFloat maxOffset = (kItemWidth + flowLayout.minimumInteritemSpacing) * kMaxCount;
NSInteger item = (targetContentOffset->x / (kItemWidth + flowLayout.minimumInteritemSpacing));
NSIndexPath *targetPath = [NSIndexPath indexPathForItem:item inSection:0];
UICollectionViewLayoutAttributes *attrs = [self.collectionView layoutAttributesForItemAtIndexPath:targetPath];
DebugLog(@"target cell attrs: %@", attrs);
@cbess
cbess / split-cell-animation.m
Last active August 29, 2015 13:56
Split UICollectionViewCell (or any view) into two pieces, then send (animation off screen) in opposite directions.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
// we are placing it above the collection view, in the VC.view,
// so convert the rect to that coord. region
CGRect cellRect = [collectionView convertRect:cell.frame toView:self.view];
CGRect cellBounds = cell.bounds;
// get an image of the cell
@cbess
cbess / cmd-app-script.scpt
Created February 14, 2014 06:04
Command line access with AppleScript
-- open Terminal and do stuff
tell application "Terminal"
set currentTab to do script ("python")
delay 1
do script ("import sys") in currentTab
do script ("sys.path") in currentTab
delay 1
--close front window
@cbess
cbess / realm-helper.swift
Created February 14, 2015 07:23
Realm Helper
import Foundation
/**
Provides the default transaction block for perform a Realm transaction.
:param: block The block to perform the transaction. The realm is used to store the transaction.
*/
func realmTransaction(block: (realm: RLMRealm) -> Void) {
let realm = RLMRealm.defaultRealm()
@cbess
cbess / hapi-https.js
Last active August 29, 2015 14:19
hapi https
var options = {
tls: {
key: fs.readFileSync(path.join(__dirname, "private/key/key.pem"), 'utf-8'),
cert: fs.readFileSync(path.join(__dirname, "private/key/certificate.pem"), 'utf-8')
}
};
var https = new hapi.Server("localhost", configuration["api-port"], options);
@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 / 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: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: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)