Skip to content

Instantly share code, notes, and snippets.

View charliewilco's full-sized avatar
🦕
...

Charlie ⚡️ charliewilco

🦕
...
View GitHub Profile
// 1. What is the difference between an array and a set?
// ---
const values = [];
const _values = new Set();
// 2. What is the difference between an object and a map?
// ---
const dict = {};
const data = ["a", "b", "c", "d", "e", "e", "c"];
function checkDuplicates(data) {
const n = new Map();
for (let i = 0; i < data.length; i++) {
const element = data[i];
if (n.has(element)) {
return i;
}
import Cocoa
import SwiftUI
import ServiceManagement
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var statusBarItem: NSStatusItem!
interface StringTMap<T> {
[key: string]: T;
}
export function storageMock() {
let storage: StringTMap<string> = {};
return {
setItem(key: string, value: any) {
storage[key] = value || "";
@charliewilco
charliewilco / apollo-next.tsx
Created September 27, 2019 03:41
Apollo & Next
import * as React from "react";
import Head from "next/head";
import { ApolloProvider } from "@apollo/react-hooks";
import { ApolloClient } from "apollo-client";
import { InMemoryCache, NormalizedCacheObject } from "apollo-cache-inmemory";
import { HttpLink } from "apollo-link-http";
import fetch from "isomorphic-unfetch";
import { NextPage } from "next";
let apolloClient = null;
function countingValleys(n, s) {
let seaLevel = 0;
let currLevel = 0;
let valleys = 0;
s = s.split('');
for (let i = 0; i < s.length; i++) {
//update the current level
if (s[i] === 'U') {
currLevel += 1;
/*
Name: Duotone Ganymede
*/
:root {
--keyword: #3274a9;
--tag: #e2a500;
--prev-normal: #4a5f78;
--normal: #143550;
--script: #e56353;
@charliewilco
charliewilco / night-mode.js
Created October 12, 2018 08:20
Night Mode + Localstorage
import React from "react";
const Night = React.createContext({});
export class NightModeProvider extends React.Component {
static defaultProps = {
className: "NightMode"
};
state = {
FROM mhart/alpine-node:10
WORKDIR /usr/src/app
COPY package.json ./
# # add files to container
# ADD . /app
# # specify the working directory
function NodeCookieParser(req) {
let cookies = {};
req.headers.cookie &&
req.headers.cookie.split(";").forEach(function(cookie) {
let parts = cookie.split("=");
cookies[parts[0].trim()] = (parts[1] || "").trim();
});
return cookies
}