Skip to content

Instantly share code, notes, and snippets.

View Qijiang60's full-sized avatar

Qi Jiang Qijiang60

  • Nanchang, Jiangxi
View GitHub Profile

The three design patterns (Adapter, Facade and Bridge) all produce the result of a clean public API. The difference between the patterns are usually due to a subtle context shift (and in some cases, a behavioural requirement).

Adapter

The primary function of an Adapter is to produce a unified interface for a number of underlying and unrelated objects.

You will notice this pattern being utilised in many applications. For example, ActiveRecord (the popular Ruby ORM; object-relational mapping) creates a unified interface as part of its API but the code underneath the interface is able to communicate with many different types of databases. Allowing the consumer of the API to not have to worry about specific database implementation details.

The principle structure of this pattern is:

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:
@Qijiang60
Qijiang60 / curl.md
Created November 10, 2016 15:17 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
package com.atlassian.stash.plugin.webook;
import com.atlassian.stash.event.pull.PullRequestRescopedEvent;
import com.atlassian.stash.hook.repository.AsyncPostReceiveRepositoryHook;
import com.atlassian.stash.hook.repository.RepositoryHookContext;
import com.atlassian.stash.nav.NavBuilder;
import com.atlassian.stash.pull.PullRequestRef;
import com.atlassian.stash.repository.RefChange;
import com.atlassian.stash.repository.RefChangeType;
import com.atlassian.stash.repository.Repository;
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html">
<title>Github API Webapp using jQuery - Treehouse Demo</title>
<meta name="author" content="Jake Rocheleau">
<link rel="shortcut icon" href="http://d15dxvojnvxp1x.cloudfront.net/assets/favicon.ico">
<link rel="icon" href="http://d15dxvojnvxp1x.cloudfront.net/assets/favicon.ico">
<link rel="stylesheet" type="text/css" media="all" href="css/styles.css">
@Qijiang60
Qijiang60 / 00-notes.md
Created January 20, 2017 17:04 — forked from gibson042/00-notes.md
jQuery.xhr

AJAX Examples

jQuery.xhr will be an asynchronous HTTP request API returning standards-compliant thenables. We have identified two possible approaches:

  • Autosend: control by options parameter; advanced functionality via beforeSend (similar to jQuery.ajax)
  • Chainable: control by options and/or chainable setters; advanced functionality via send: false and a chainable send method

This gist compares the approaches by imagining their use for current jQuery.ajax examples. To better highlight differences, chaining methods will be used instead of options more heavily than is likely in actual practice (assuming that options is available in the "Chainable" solution).

@Qijiang60
Qijiang60 / services.md
Created January 31, 2017 14:34 — forked from shipstar/services.md
GitHub + Kanban

Spent a couple minutes poking around at kanban-like alternatives/supplements to labeling:

GitHub uses this and Huboard internally for some projects. Supported by Rally, so probably not going away anytime soon.

GitHub uses this and Waffle internally for some projects.

Looks interesting. (Marking issues from the command-line? Sweet!) It's also pricey.

@Qijiang60
Qijiang60 / authentication-request-token-jquery.js
Created February 23, 2017 15:56 — forked from boomtrain-support/authentication-request-token-jquery.js
API Authentication - An example to request an OAuth token using jQuery
$.ajax({
url: 'https://api.boomtrain.com/tokens',
headers: {
'x-app-id': '{app_id}',
'Authentication': 'Basic ' + btoa('{username}:{password}')
},
...
});
@Qijiang60
Qijiang60 / jsonp
Created March 3, 2017 18:57 — forked from malsup/jsonp
$.getJSONP
// fn to handle jsonp with timeouts and errors
// hat tip to Ricardo Tomasi for the timeout logic
$.getJSONP = function(s) {
s.dataType = 'jsonp';
$.ajax(s);
// figure out what the callback fn is
var $script = $(document.getElementsByTagName('head')[0].firstChild);
var url = $script.attr('src') || '';
var cb = (url.match(/callback=(\w+)/)||[])[1];
@Qijiang60
Qijiang60 / gist:f00ca07e7e78ed040077cd3d6784fc7c
Created April 11, 2017 17:40 — forked from alexschwartz/gist:912787
Ask Jenkins via json using jquery
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Seitenr?nder - marginwidth, marginheight, topmargin, leftmargin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var baseUrl;