Skip to content

Instantly share code, notes, and snippets.

View wesleycho's full-sized avatar

Wesley Cho wesleycho

View GitHub Profile
@wesleycho
wesleycho / query.json
Last active February 10, 2016 14:58
GET https://www.googleapis.com/youtube/v3/videos params - part = ['snippet', 'contentDetails', 'status', 'statistics'] id = video id (can be array)
{
"kind": "youtube#videoListResponse",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/9PT9LvCT4m7dStngSaVcA3wA4VE\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
@wesleycho
wesleycho / foo.ts
Last active February 4, 2016 18:55
@Directive({
host: {
'(click)': 'goToRoute($event)',
'(keydown)': 'goToRoute($event)'
}
})
class MyRouteHandler {
@Input() route;
constructor(private _router: Router) {}
goToRoute(evt: Event | KeyboardEvent) {
@wesleycho
wesleycho / function.js
Last active January 20, 2016 19:39 — forked from icfantv/function.js
Username Validation
vm.username = function($viewValue, $modelValue, scope) {
// check if username matches regex before validating
var value = $modelValue || $viewValue, deferred = $q.defer();
if (UserConfig.ID_REGEX.test(value)) {
scope.options.templateOptions.loading = true;
UserService.username(value).then(function() {
deferred.reject(false);
function matchPeople (list, idx) {
var randomNumber = Math.floor(Math.random() * list.length);
if (list[randomNumber] === list[idx]) {
return matchPeople(list, idx);
}
else {
idx++;
$scope.match.push(list[randomNumber]);
if (list.length === 1) {
@wesleycho
wesleycho / gist:1a904893add7e64c464f
Last active August 29, 2015 14:06
React grid with angular psuedocode
module.directive('react-grid', function () {
return {
scope: { props: '=' },
link: function (scope, elem, attrs) {
var renderScheduled = false;
var component = React.createClass({
/** @jsx React.DOM */
var items = this.props.items;
var itemsDOM = items.map(function (item) {
var itemDOM = item.map(function (subItem) {
if($scope.new_user_info.isLocation)
{
if(!$scope.new_user_info.location_id)
{
Location.create($scope.new_user_info.location).success(function(newLocation){
$scope.new_user_info.location_id = newLocation.id;
$scope.new_location = {};
successAddLocation = true;
}).error(function(data, status, header, config) {
if(status == 500)
'use strict';
printio.controller('ProductDetailsCtrl', function($scope, $routeParams, $filter, Printio) {
Printio.getProducts()
.then(fetchProduct)
.then(getShipEstimate)
.then(openProduct)
function fetchProduct(data) {
app.factory('api', ['$http', '$q', '$log', function($http, $q, $log) {
return {
last: function(market, currency){
$log.log('api/last', currency, 'market', market);
//return the promise directly.
return $http.get('/api/last/'+market+'/'+currency)
.then(function(result) {
//resolve the promise as the data
$log.log('api.last data', result.data);
var app = angular.module('TradeList', [
'ngAnimate'
, 'ngRoute'
], function(
$locationProvider
, $routeProvider
) {
$locationProvider.html5Mode(true);
$routeProvider.when('/', {
templateUrl: '/assets/views/orders.html'
@wesleycho
wesleycho / gist:6141245
Created August 2, 2013 16:23
module.provider() example
angular.module('myApp', [])
.provider('greeterProvider', function () {
var greeting = 'Hello!'
this.greeting = function (name) {
return 'Hello ' + name + '!';
});
function Greeter() {
this.greet = function () {
return greeting;