Skip to content

Instantly share code, notes, and snippets.

@jeffhuangtw
jeffhuangtw / gist:01ea94bc0cb801f67272
Created February 25, 2015 03:17
Parse.com cloud code to prevent users from making duplicate submissions
Parse.Cloud.beforeSave("Requests", function(request, response) {
var postObj = new Parse.Object("Posts");
postObj.set("objectId", request.object.get("Post_Pointer"));
var query = new Parse.Query("Requests");
query.equalTo("Post_Pointer", postObj);
query.equalTo("Requester", Parse.User.current());
query.first({
success: function(object) {
if (object) {
@jeffhuangtw
jeffhuangtw / gist:67d2c2a33eeb3c6644ce
Created February 26, 2015 02:30
parse cloud code sample code
Parse.Cloud.beforeSave("Posts", function(request, response) {
if (request.object.existed()) {
return response.success(); // the Post already exist, this must be an Update action
}
// do a query to "Posts" to check the oldest related "Posts" to current user
var query = new Parse.Query("Posts");
query.equalTo("PostUser", Parse.User.current());
query.equalTo("Topic", YOUR_REFERENCED_TOPIC_OBJECT); // assume you are want to reference it by pointer
query.descending("createdAt");
@jeffhuangtw
jeffhuangtw / .js
Created July 30, 2015 02:38
parse duplicate save bug sample code
Parse.Cloud.define("testSave", function(request, response) {
var id = request.params.class1Id;
var query = new Parse.Query('Class1');
query.include('Class2Pointer');
query.get(id).then(function (Class1) {
var Class2 = Class1.get('Class2Pointer');
Class2.set('text', 'snoopy');
// test 1: this will have duplicate save two times
Class2.set('Class1Pointer', Class1);
// test 2: this will save once
@jeffhuangtw
jeffhuangtw / SoftKeyboard.java
Last active August 29, 2015 14:27 — forked from felHR85/SoftKeyboard.java
A solution to catch show/hide soft keyboard events in Android http://felhr85.net/2014/05/04/catch-soft-keyboard-showhidden-events-in-android/
/*
* Author: Felipe Herranz (felhr85@gmail.com)
* Contributors:Francesco Verheye (verheye.francesco@gmail.com)
* Israel Dominguez (dominguez.israel@gmail.com)
*/
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import android.os.Handler;
@jeffhuangtw
jeffhuangtw / gist:273455305ff8c39d1099
Created August 24, 2015 07:41
Test fetch and upload multiple ParseFile with Promise
Parse.Cloud.define("TestUpload", function(request, response) {
var attachmentURLs = [];
attachmentURLs.push({'name': 'gogole_logo', 'url': 'https://www.google.com.tw/intl/en_ALL/images/srpr/logo11w.png', 'content-type': 'image/png'});
attachmentURLs.push({'name': 'yahoo_logo', 'url': 'https://www.google.com.tw/images/nav_logo225.png', 'content-type': 'image/png'});
var promises = [];
attachmentURLs.forEach(function(file){
promises.push(Parse.Cloud.httpRequest({
url: file.url,
}).then(function(fetchedFile){
@jeffhuangtw
jeffhuangtw / gist:751178dd0c3873449747
Last active September 25, 2015 16:19
dirty sample for Parse Job query.each and push something
var queryAllUser = new Parse.Query(Parse.User);
Parse.Cloud.useMasterKey();
queryAllUser.each(function(user) {
var queryMatch = new Parse.Query(Parse.User);
queryMatch.containedIn("offer", user.get("search"));
return query.find().then(function(users) {
if (users.length >0) {
var targetList = [];
for (i = 0; i < users.length; i++) {
var userPointer = Parse.Object.extend(Parse.User);
@jeffhuangtw
jeffhuangtw / sample.js
Created October 2, 2015 17:03
Resend Parse User Verification Email Cloud Code
// resend verify email
Parse.Cloud.define("ResendVerifyEmail", function(request, response) {
var user = Parse.User.current();
if (!user) {
response.error("INVALID_USER");
return;
}
var email = request.params.email;
var query = new Parse.Query(Parse.User);
Parse.Cloud.useMasterKey();
@jeffhuangtw
jeffhuangtw / gist:541e7b5ad6701671ce06
Created January 6, 2016 12:26
machine learning note
Coursera course
https://www.coursera.org/learn/machine-learning
Week 1 Note:
Partial derivative in gradient descent for two variables
https://math.stackexchange.com/questions/70728/partial-derivative-in-gradient-descent-for-two-variables/189792#189792
Gradient descent
https://www.youtube.com/watch?v=WnqQrPNYz5Q&ab_channel=AlexanderIhler
@jeffhuangtw
jeffhuangtw / sample.js
Created March 15, 2017 09:52
[nodejs] server side check "androidpublisher.purchases.subscriptions.get" with "service account"
// Google Play API Key
// ref: http://stackoverflow.com/questions/35127086/android-inapp-purchase-receipt-validation-google-play
// ref: https://developers.google.com/android-publisher/authorization
// ref: http://google.github.io/google-api-nodejs-client/18.0.0/index.html#toc14__anchor
//
// install npm package
// ref: https://github.com/google/google-api-nodejs-client
// $ npm install googleapis --save
//
const google = require('googleapis');
@jeffhuangtw
jeffhuangtw / gist:e64fa7eabf6e16e01842e76ff53ba233
Created September 18, 2017 09:30
[Visual Studio Code] [nodejs] [debugger] [foreman] vsc + foreman + debugger
// 1. add a executable dev.sh to run your script (example: web.js)
#!/bin/bash
node --inspect web.js
// 2. install foreman
$ npm install -g foreman
// 3. prepare your environment variables file
$ touch .env