Skip to content

Instantly share code, notes, and snippets.

@ktcy
ktcy / webrtc-client.js
Last active November 27, 2018 11:12
WebRTC sample
const clientList = document.getElementById('client-list');
const mainVideo = document.getElementById('main-video');
mainVideo.addEventListener('loadedmetadata', () => {
const {videoWidth, videoHeight} = mainVideo;
const longest = Math.max(videoWidth, videoHeight);
const size = 300;
mainVideo.width = size * videoWidth / longest;
mainVideo.height = size * videoHeight / longest;
@ktcy
ktcy / silence.js
Created October 24, 2018 10:20
Create WAV file containing only silence
function createSilence(seconds = 1) {
const sampleRate = 8000;
const numChannels = 1;
const bitsPerSample = 8;
const blockAlign = numChannels * bitsPerSample / 8;
const byteRate = sampleRate * blockAlign;
const dataSize = Math.ceil(seconds * sampleRate) * blockAlign;
const chunkSize = 36 + dataSize;
const byteLength = 8 + chunkSize;
@ktcy
ktcy / index.html
Last active July 10, 2019 23:52
Spotify API Authorization
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example of the Authorization Code flow with Spotify</title>
<style type="text/css">
#login, #loggedin {
display: none;
}
.text-overflow {
@ktcy
ktcy / circumcircle.js
Created April 20, 2017 09:03
Circumcircle from three points
function circumcircle(point0, point1, point2) {
const x1 = point1.x - point0.x;
const y1 = point1.y - point0.y;
const x2 = point2.x - point0.x;
const y2 = point2.y - point0.y;
const k = 2 * (x1 * y2 - y1 * x2);
if (k === 0) {
return null;
}

Default settings to generate image assets for Android

Create empty layer and name it:

default 100% drawable-mdpi/ + 150% drawable-hdpi/ + 200% drawable-xhdpi/ + 300% drawable-xxhdpi/

Reference:

@ktcy
ktcy / CubicBezier.es6.js
Created September 18, 2015 11:35
CSS `cubic-bezier()` timing function
'use strict';
export default function cubicBezier(x1, y1, x2, y2) {
let ax, bx, cx, ay, by, cy;
ax = 3 * (x1 - x2) + 1;
bx = 3 * x2 - 6 * x1;
cx = 3 * x1;
ay = 3 * (y1 - y2) + 1;
'use strict';
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
@ktcy
ktcy / invpath
Last active August 29, 2015 14:27
$ invpath <path>
#!/usr/bin/env node
getOptions(function(options) {
if (!options.path) {
console.log('Usage: invpath <path>');
process.exit(0);
}
var path = options.path.trim();
var type = guess(path);
@ktcy
ktcy / toremote
Last active August 29, 2015 14:27
$ toremote [--mac] [--windows] [path]
#!/usr/bin/env node
try {
var args = parseArguments();
if (args.help) {
console.log('Usage: toremote [--mac] [--windows] [path]');
process.exit(0);
}
function gaussianElimination(matrix) {
var pivot, base, col, div, mul, v, n, i, j;
n = matrix.length;
// Forward Elimination
for (pivot = 0; pivot < n - 1; pivot++) {
swap(matrix, pivot);
base = matrix[pivot];