Skip to content

Instantly share code, notes, and snippets.

View chengscott's full-sized avatar

Scott Cheng chengscott

View GitHub Profile
@chengscott
chengscott / typeahead_parse.js
Last active October 10, 2015 10:15
Twitter typeahead dynamic source from Parse.com
var ShopData = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://api.parse.com/1/classes/Shop?where={"name":{"$regex":"%QUERY"}}&limit=20',
wildcard: '%QUERY',
prepare: function (query, settings) {
// settings.type (method for jQuery 1.9+) default is GET
settings.dataType = 'json';
settings.contentType = "application/json; charset=UTF-8";
@chengscott
chengscott / Guide.cs
Last active May 13, 2021 06:46
C# ListViewColumnSorter with NEW and AUTO key
// 1. Paste the following code into the class for the form:
private ListViewColumnSorter lvwColumnSorter = new ListViewColumnSorter();
// 2. Paste the following code into the constructor for the form, after the call to the InitializeComponent method:
this.listView1.ListViewItemSorter = lvwColumnSorter;
// 3. Paste the following code into the ColumnClick event for the ListView control:
@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;