Skip to content

Instantly share code, notes, and snippets.

Parse.Cloud.beforeSave(Parse.Role, function(request, response) {
Parse.Cloud.useMasterKey();
var role = request.object;
if (user_js.isAdministratorRole(role)) {
if (role.isNew()) {
// Administrator role creation
// Set ACL on create
var administratorRoleACL = new Parse.ACL();
administratorRoleACL.setPublicReadAccess(false);
administratorRoleACL.setPublicWriteAccess(false);
@akisute
akisute / dice.py
Last active December 16, 2015 11:09
Random is fun
#!/usr/bin/env python
import random
# n = 50
# d = 2
# a = 25
# cnt = 1000000
# result = {}
# for _ in range (cnt):
# values = [random.randrange(d)+1 for _ in range(n)]
# v = sum(values) - a
@akisute
akisute / gist:5343778
Created April 9, 2013 07:49
こんなかんじのイニシャライザ書いてた
class Data(object):
def __init__(self, **kwargs):
self.t = None #
self.m = -1 #
self.dI = None #
self.dS = None #
self.dM = None #
self.dG = 0 #
initialize_model(self, **kwargs)
@akisute
akisute / main.js
Created March 20, 2013 15:01
Writing some simple app with Parse Cloud Code
/**
* Example function
*/
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello, CardGame Cloud Code!");
});
/**
* Draw a new booster pack gacha of MCards from an unlimited card pool.
* (which means, this is not a "box gacha")
@akisute
akisute / ADMWaitingForLoginViewController.m
Created March 17, 2013 07:16
Parseまじめに使ったadmin用ログインビュー
//
// ADMWaitingForLoginViewController.m
// CardGame
//
// Created by 小野 将司 on 2013/03/17.
// Copyright (c) 2013年 akisute. All rights reserved.
//
#import <Parse/Parse.h>
#import <Parse/PF_MBProgressHUD.h>
@akisute
akisute / gist:5180299
Created March 17, 2013 05:38
いくばくかマシに
- (void)signUpViewController:(PFSignUpViewController *)signUpController didFailToSignUpWithError:(NSError *)error
{
DNSLogError(@"Error while signing up: %@", error);
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.title = @"Error while sigining up";
alertView.message = error.localizedDescription;
[alertView addButtonItem:[RIButtonItem itemWithLabel:@"OK" action:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:NULL];
});
@akisute
akisute / gist:5180294
Created March 17, 2013 05:37
うーわキモッ
- (void)signUpViewController:(PFSignUpViewController *)signUpController didFailToSignUpWithError:(NSError *)error
{
DNSLogError(@"Error while signing up: %@", error);
[[[UIAlertView alloc] initWithTitle:@"Error while sigining up"
message:error.localizedDescription
cancelButtonItem:[RIButtonItem itemWithLabel:@"OK" action:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:NULL];
});
}]
@akisute
akisute / SLComposeViewControllerFailsFacebook.mm
Last active December 11, 2015 08:59
SLComposeViewController fails sharing with Facebook when you add a "blank" NSURL instance
- (void)succeed1
{
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[vc addURL:[NSURL URLWithString:@"http://akisute.com"]];
[self.navigationController presentViewController:vc animated:YES completion:nil]; // posts with a link, no error
}
- (void)succeed2
{
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
#!/usr/bin/env ruby
require 'rubygems'
require 'xcodeproj'
require 'pathname'
require 'fileutils'
#
# Define utility functions
#
def add_system_frameworks_to_project(proj, framework_names, option=:required)
[super viewWillAppear:animated];
NSManagedObjectContext *context = [NSManagedObjectContext MR_contextForCurrentThread];
// ここで、FEUnitはFEClanに対してclanというrelationを持っているとする
// FEClanはFEUnitに対してunitsというrelationを持っているとする
// NSManagedObjectIDで検索
// Property clanID must be permanent since a temporary ID cannot handle this query
self.fetchedResultsController = [FEUnit MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"clan == %@", self.clanID]