Skip to content

Instantly share code, notes, and snippets.

View chengscott's full-sized avatar

Scott Cheng chengscott

View GitHub Profile
@chengscott
chengscott / stop.js
Last active August 29, 2015 14:25
window.stop()
// Solution for window.stop(); in MSIE and Trident aka Edge
if (navigator.userAgent.match(/Trident|MSIE/) != null) {
document.execCommand("Stop");
} else {
window.stop();
}
@chengscott
chengscott / grecaptcha.js
Last active August 29, 2015 14:25
Parse Cloud Code - grecaptcha
Parse.Cloud.define("grecaptcha", function (request, response) {
Parse.Cloud.httpRequest({
url: 'https://www.google.com/recaptcha/api/siteverify?secret=<Your Secret Key here>&response=' + request.params.key,
success: function (httpResponse) {
response.success(JSON.parse(httpResponse.text).success);
}
});
});
@chengscott
chengscott / role.js
Created July 25, 2015 05:50
Parse Cloud Code - new user add to a role
Parse.Cloud.afterSave("_User", function (request, response) {
Parse.Cloud.useMasterKey();
var user = request.object;
query = new Parse.Query(Parse.Role);
// add user to the role named "General"
query.equalTo("name", "General");
query.first({
success: function (object) {
object.relation("users").add(user);
object.save();
@chengscott
chengscott / ScaleNetworkImageView.java
Last active August 29, 2015 14:26
Google Volley scalable NetworkImageView
// LICENSE : https://gist.github.com/52c13856a6d59acaa86f.git
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
@chengscott
chengscott / ShopProxy.java
Last active August 29, 2015 14:26
Parcelable example
// LICENSE : https://gist.github.com/52c13856a6d59acaa86f.git
import android.os.Parcel;
import android.os.Parcelable;
public class ShopProxy implements Parcelable {
private static final long serialVersionUID = 1L;
private String name, category, description;
private boolean takeout, authorized;
private double latitude, longtitude;
@chengscott
chengscott / Shop.java
Last active August 29, 2015 14:26
Parse.com ParseObject subclass example
// LICENSE : https://gist.github.com/52c13856a6d59acaa86f.git
import com.parse.ParseClassName;
import com.parse.ParseGeoPoint;
import com.parse.ParseObject;
@ParseClassName("Shop")
public class Shop extends ParseObject {
public Shop() {
// A default constructor is required.
@chengscott
chengscott / LICENSE
Created July 31, 2015 01:08
Some of my gists apply to the MIT LICENSE.
The MIT License (MIT)
Copyright (c) 2015 Scott Cheng <60510scott@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@chengscott
chengscott / FadeInNetworkImageView.java
Last active August 29, 2015 14:26 — forked from benvd/FadeInNetworkImageView.java
Extension of Volley's NetworkImageView that fades in images as they're loaded
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.*;
import android.util.AttributeSet;
import com.android.volley.toolbox.NetworkImageView;
public class FadeInNetworkImageView extends NetworkImageView {
private static final int FADE_IN_TIME_MS = 250;
@chengscott
chengscott / Connectivity.java
Last active August 29, 2015 14:26 — forked from emil2k/Connectivity.java
Android utility class for checking device's network connectivity and speed.
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil
@chengscott
chengscott / Main.java
Created August 6, 2015 04:00
Google Volley ImageRequest setPriority
PriorityImageRequest request = new PriorityImageRequest(url, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
((ImageView) getActivity().findViewById(R.id.imageView)).setImageBitmap(bitmap);
}
}, /*maxWidth*/0, /*maxHeight*/0, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}