Skip to content

Instantly share code, notes, and snippets.

@kaleidawave
kaleidawave / Section.cs
Last active May 12, 2019 13:50
Functions for working with 2D array
using System.Drawing;
namespace Extensions
{
public static class ArrayExtensions
{
public static Rectangle Expand(this Rectangle r, int factor)
{
return new Rectangle(r.X * factor, r.Y * factor, r.Width * factor, r.Height * factor);
}
@kaleidawave
kaleidawave / Promise.cs
Last active April 23, 2019 13:09
Implementation of the javascript process api in csharp
using System;
public class Promise<T>
{
private T _value;
public Promise(T value) {
this._value = value;
}
@kaleidawave
kaleidawave / functions>index.js
Created July 6, 2019 19:07
Pass image files through firebase function arguments
exports.uploadImage = functions.https.onCall(async (data, context) => {
const mimeType = data.image.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/)[1];
const base64EncodedImageString = data.image.replace(/^data:image\/\w+;base64,/, '');
const imageBuffer = new Buffer(base64EncodedImageString, 'base64');
const filename = `posts/${data.name}.${mimeTypes.detectExtension(mimeType)}`;
const file = admin.storage().bucket().file(filename);
await file.save(imageBuffer, { contentType: 'image/jpeg' });
const photoURL = await file.getSignedUrl({ action: 'read', expires: '03-09-2491' }).then(urls => urls[0]);
@kaleidawave
kaleidawave / numofcoins.py
Created August 13, 2019 11:28
The num of coins that are returned in change as mentioned in the first question of this interview https://www.youtube.com/watch?v=HWW-jA6YjHk
coins = [25, 10, 5, 1]
def num__of_coins(cents):
if cents == 0:
return 0
numOfCoins = 0
while cents > 0:
for coin in coins:
if cents >= coin:
cents -= coin
@kaleidawave
kaleidawave / README.md
Last active February 24, 2020 09:16
Web component parsing issue

It seems that web components initial properties are different based on when they are defined. component-two is defined after the dom has loaded whereas the defintion for component-one is loaded while the browser is parsing the html. The browser seems to fire of its coresponding component connectedCallback() on the end of its start tag rather than going though to the end / closing tag.

Console output:

innerHTML: ""
innerHTML: "I also have innerHTML"
Fixes:
Hello World
<template>
<h1>Counter</h1>
<span>{count}</span>
<button @click="increment">Add One</button>
<button @click="decrement">Subtract One</button>
</template>
<script>
@TagName("counter-component")
@Default({count: 5})
@kaleidawave
kaleidawave / use-width-component.prism
Created November 14, 2020 10:14
Following: https://twitter.com/AdamRackis/status/1327061880855273473. Note this is different as Adam's implementation is a reusable hook whereas this is baked into this component.
<template>
<h1>Component width: {width}</h1>
</template>
<script>
class ResizeAwareComponent extends Component<{width: number}> {
ro: ResizeObserver
connected() {
this.data.width = this.offsetWidth;
@kaleidawave
kaleidawave / main.rs
Created November 25, 2020 21:21
Tokenizer in Rust
#[derive(Debug)]
struct Token<T> {
token_type: T,
value: Option<String>
}
#[derive(Debug, PartialEq)]
enum JSToken {
NumberLiteral,
AddOperator,
import * as semver from "https://deno.land/x/semver/mod.ts";
import {existsSync} from "https://deno.land/std@0.103.0/fs/exists.ts";
import * as toml from "https://deno.land/std@0.103.0/encoding/toml.ts";
function bumpVersion(existingVersion, versionArgument) {
if (semver.valid(versionArgument)) {
return versionArgument;
} else {
return semver.inc(existingVersion, versionArgument);
}