Skip to content

Instantly share code, notes, and snippets.

View iamgoangle's full-sized avatar
:octocat:
Focusing

Teerapong Singthong iamgoangle

:octocat:
Focusing
View GitHub Profile
@iamgoangle
iamgoangle / index.html
Created November 24, 2015 16:25
Example RequireJS
<!DOCTYPE html>
<html>
<head>
<title>01 - Introduction of RequireJS</title>
<script data-main="../js/mainApp.js" src="../js/require.js"></script>
</head>
<body>
<h3>
RequireJS is a JavaScript file and module loader. It is optimized for in-browser use,
but it can be used in other JavaScript environments,
@iamgoangle
iamgoangle / controller.js
Last active December 26, 2015 16:09
AngularJS $parsers and $formatters
<script>
/*
Definition
$parsers/$formatters are an array of actions that take in input,
translate it to either the computer-friendly or human-friendly format respectively
and return the translated value.
Formatters change how model values will appear in the view.
Parsers change how view values will be saved in the model.
@iamgoangle
iamgoangle / test.html
Created January 5, 2016 16:40
AngularJS Parsers Formatters
<!DOCTYPE html>
<html ng-app="testApp">
<head>
<title>01_simple_directive.html</title>
<script type="application/javascript" src="angular.min.js"></script>
<script>
var testApp = angular.module('testApp', []);
@iamgoangle
iamgoangle / products.js
Last active June 10, 2017 12:18
products.js
// products.js
var faker = require('faker');
function generateProducts () {
let products = [];
for (var id = 0; id < 50; id++) {
var productName = faker.commerce.productName();
var price = faker.commerce.price();
var qty = faker.finance.amount();
const path = require('path');
let mockFile = (schema) => {
return require(path.join(__dirname, 'mock/', schema));
};
module.exports = () => {
return {
customers: mockFile('customers.js'),
products: mockFile('products.js')
@iamgoangle
iamgoangle / registering-sw.js
Last active June 10, 2017 18:10
Install Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
@iamgoangle
iamgoangle / sw.js
Created June 11, 2017 14:46
Install service worker
self.addEventListener('install', function(event) {
// Perform install steps
});
@iamgoangle
iamgoangle / sw.js
Created June 11, 2017 15:46
Fetch cache
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
@iamgoangle
iamgoangle / sw.js
Created June 11, 2017 16:04
Complete code
// sw.js
// config cache
const CACHE_NAME = 'my-site-cache-assets';
const urlsToCache = [
'/',
'index.html',
'/favicon.ico',
'/assets/rubber-duck.png'
];
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Buffet
{
public struct Rules
{
public int discount;