Skip to content

Instantly share code, notes, and snippets.

@zladuric
zladuric / app.js
Created March 6, 2019 15:04
Super-quick and dirty demo of web components
'use strict';
window.onload = function() {
const TILE_TYPES = {
FULL: 'full',
EMPTY: 'empty',
HALF_FULL: 'half-full',
};
const template = document.getElementById('tile');
class TileElement extends HTMLElement {
connectedCallback () {
# Security headers
# HSTS. Tell the browser only to access via https, and include subdomains as well.
add_header Strict-Transport-Security "max-age=2592000; includeSubDomains; preload";
# Tell the browser not to include our page as a frame in other pages.
add_header X-Frame-Options DENY;
# Tell the browser not to guess what type the file is
add_header X-Content-Type-Options nosniff;
## Tell the browser to only execute scripts included from our domain or www.some-analytics.com
add_header Content-Security-Policy "default-src 'self' www.some-analytics.com;";
# Cross site prot headers. Block rendering if CSS detected.
[{"ts":2.4710999999952037,"k":"T"},{"ts":2.6937999999936437,"k":"h"},{"ts":2.737599999993108,"k":"i"},{"ts":2.8377000000036787,"k":"s"},{"ts":2.9496999999973923,"k":" "},{"ts":3.104399999996531,"k":"i"},{"ts":3.189199999993434,"k":"s"},{"ts":3.284700000003795,"k":" "},{"ts":3.619200000001001,"k":"m"},{"ts":3.704700000002049,"k":"e"},{"ts":3.808900000003632,"k":"r"},{"ts":3.9293000000034226,"k":"e"},{"ts":4.0653999999922235,"k":"l"},{"ts":4.2013999999908265,"k":"y"},{"ts":4.423999999999069,"k":" "},{"ts":4.604299999991781,"k":"t"},{"ts":4.642200000002049,"k":"h"},{"ts":4.749199999991106,"k":"e"},{"ts":4.862599999993108,"k":" "},{"ts":5.052499999990687,"k":"b"},{"ts":5.161800000001676,"k":"e"},{"ts":5.389499999990221,"k":"g"},{"ts":5.455099999991944,"k":"i"},{"ts":5.531399999992573,"k":"n"},{"ts":5.809500000003027,"k":"n"},{"ts":6.178399999989779,"k":"i"},{"ts":6.241200000004028,"k":"n"},{"ts":6.375399999989895,"k":"g"},{"ts":6.563500000003842,"k":"."},{"ts":6.749400000000605,"k":" "},{"ts":7.933699999994133,"k
const request = require('request');
function callRemoteApi(url) {
return new Promise((resolve, reject) => {
console.log('Fetching', url);
request(url, (err, res) => {
if (err) {
return reject(err);
}
console.log('Got', url);
Animations with Angular
Typing this as a reminder on how to do certain animations with Angular4. Because I'll forget by next week.
Steps:
0. Prerequisits - BrowserAnimationsModule into the main app module
1. Define animations - `export const myAnimation = trigger(':nameOfAnimation', [ <list of transitions or states> ]);
2. Import `myAnimation` into the needed components
3. Bind as attributes, e.g. `[@myAnimation]="stateVariable"`
it('should upload a file', function() {
const request = require('request');
const headers = {
'Accept': '*/*',
'Origin': 'http://localhost:5555',
'x-amz-acl': 'public-read',
'Content-Type': 'video/quicktime',
};
const options = {
headers,
import { Component, Injectable, Directive, Input, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import {
async,
TestBed,
ComponentFixture
} from '@angular/core/testing';
import { SharedModule } from './shared/shared.module';
// Demonstrating a point for: http://stackoverflow.com/questions/41814637/javascript-function-definition-explanation/41814751?noredirect=1#comment70848676_41814751
> [zlatko@zlatko-desktop ~]$ node
> function outer() {
... set();
... (function set() {})();
... }
undefined
> outer()
ReferenceError: set is not defined
at outer (repl:2:1)
// Create something to test
db.test.insert({deep: {prop: 5}});
// Rename field
db.test.update({'deep.prop': {$exists: true}}, {$rename: {'deep.prop': 'deep.property'}}, {multi: true});
// Move to another object
// Note: leaves dangling `deep: {}`
db.test.update({'deep.property': {$exists: true}}, {$rename: {'deep.property': 'deeper.deep.property'}}, {multi: true});
@zladuric
zladuric / endpoints_with_auth.md
Last active August 29, 2015 14:15
Test REST endpoints with auth