Skip to content

Instantly share code, notes, and snippets.

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;
@adamjuhasz
adamjuhasz / header
Created October 22, 2014 22:08
Easy Data Encryption
#import <Foundation/Foundation.h>
@interface MomentEncrypter : NSValueTransformer
@property NSData *key;
@property NSData *iv;
- (void)setKeyAndIVWith:(NSString*)password;
@end
@adamjuhasz
adamjuhasz / scripts-main.js
Last active March 31, 2017 18:58
Serverless example for the alana bot framework
addGreeting((user, response) => {
response.sendText('📢 🤖')
})
newScript()
.dialog((session, response) => {
if (session.message.type === 'text') {
switch (session.message.text) {
// solved better with intents, https://www.alana.tech/concepts/intents.html
case 'hello':
const Alana = require('@alana/core').default;
const request = require('request-promise');
const flatten = require('lodash.flatten');
const Promise = require('bluebird');
const fs = require('fs');
const path = require('path');
const vm = require('vm');
// Converts FB payloads to Alana common message format
const inputConverter = require('@alana/platform-facebook').mapFBToInternal;
// Converts alana format to FB messenger
@adamjuhasz
adamjuhasz / timeout.js
Last active April 2, 2017 15:47
alana timeout responses
.dialog(function(session, response, stop) {
// always send typing indicators
response.sendTyping();
// make an api request
request({ uri: '', method: 'POST' ... })
.then(function (results) {
response.sendText(`The weather will be ${results} today`);
})
.timeout(5000) // timeout is in ms
.catch(Promise.TimeoutError, function(e) {
@adamjuhasz
adamjuhasz / json-postback.js
Last active April 3, 2017 21:29
Using json as the payload for a button click for alana
.dialog((session, response, stop) => {
const expiresIn24Hours = new Date().setHours(new Date().getHours() + 24);
response.createButtons()
.text('Choose an option')
.addButton('postback', 'Option 1', JSON.stringify({
c: 'do-this', // c is for command
s: 'current-state', // s is for state
exp: expiresIn24Hours.getTime() / 1000,
})
.addButton('postback', 'Option 2', JSON.stringify({
.dialog((session, response, stop) => {
response.sendText(getRandom([
"I'm confused",
"I don't know what you mean",
"Can you try again",
"I'm just a baby bot",
]));
})
function getRandom(arr) {
bp.hear(), (event, next) => {
bp.db.kvs.get(event.user.id)
.then(user => {
if (!user || user.step === 0) {
bp.messenger.sendText(event.user.id, 'Hello, what would you like me to call you?');
return bp.db.kvs.set(event.user.id, defaultUser);
}
if (user.step > 2) {
// already registered user do somethign else here
}
newScript().dialog((session, response) => {
if (!session.user.state.nickname) {
response.startScript('profile');
}
})
newScript('profile')
.dialog((session, response) => {
response.sendText('Hello, what would you like me to call you?');
})
bot.dialog('/', [
function (session) {
if (!session.userData.nickname) {
session.beginDialog('/profile', session.userData.profile);
}
},
function (session, results) {
session.userData.profile = results.response;
session.send('News of the day....');
}