Skip to content

Instantly share code, notes, and snippets.

View wesleycho's full-sized avatar

Wesley Cho wesleycho

View GitHub Profile
@wesleycho
wesleycho / uglyphptemplating
Created May 16, 2013 15:56
Why you don't use PHP for templating
<?php for ($i = 1; $i <= count($tracks); $i++): ?>
<div>
<ul>
<?php for ($j = 1; $j <= count($tracks[$i]); $j++): ?>
<li>
<?php
// Format of $trackName is 1-01 - artist - title - tweak as desired
$trackName = $i . '-';
if ($j <= 9) {
@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;
var app = angular.module('TradeList', [
'ngAnimate'
, 'ngRoute'
], function(
$locationProvider
, $routeProvider
) {
$locationProvider.html5Mode(true);
$routeProvider.when('/', {
templateUrl: '/assets/views/orders.html'
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);
'use strict';
printio.controller('ProductDetailsCtrl', function($scope, $routeParams, $filter, Printio) {
Printio.getProducts()
.then(fetchProduct)
.then(getShipEstimate)
.then(openProduct)
function fetchProduct(data) {
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)
@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) {
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 / 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);
@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) {