Skip to content

Instantly share code, notes, and snippets.

View cindywu's full-sized avatar
🍍
i do not want to turn into dust, but into ashes instead

Cindy Wu cindywu

🍍
i do not want to turn into dust, but into ashes instead
View GitHub Profile
@cindywu
cindywu / main.rs
Created March 4, 2021 01:58
error things
use std::fs::File;
use std::io::ErrorKind;
fn main() {
let f = File::open("hello.txt");
let _f = match f {
Ok(file) => file,
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
import React from 'react'
import { PostCard } from './PostCard'
interface Post {
abstract: any
authors: any
body: string
created_at: string
deleted_at: string
id: number
@cindywu
cindywu / connect!
Created January 10, 2021 22:41
chapter 5 create the web socket
(defn connect! [url receive-handler]
(if-let [chan (js/WebSocket. url)]
(do
(set! (.-onmessage chan) (receive-message! receive-handler))
(reset! ws-chan chan))
(throw (js/Error. "WebSocket connection failed!"))))
@cindywu
cindywu / save-message!
Created January 9, 2021 23:18
guestbook-cljs/src/clj/guestbook/routes/home.clj
(defn save-message! [{:keys [params]}]
(if-let [errors (validate-message params)]
(response/bad-request {:errors errors})
(try
(db/save-message!
(assoc params :timestamp (java.util.Date.)))
(response/ok {:status :ok})
(catch Exception e
(response/internal-server-error
{:errors {:server-error ["Failed to save message!"]}})))))
import refractor from "refractor/core";
import { flattenDeep } from "lodash";
import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view";
import { findBlockNodes } from "prosemirror-utils";
export const LANGUAGES = {
none: "None", // additional entry to disable highlighting
bash: "Bash",
css: "CSS",
@cindywu
cindywu / arrowfunctions.js
Created November 28, 2020 03:50
arrow functions javascript simplified
let printName = name => {
console.log(name)
}
let sumArrow = (a, b) => a + b
let printName = name => console.log(name)
// nope
// let printHi = name => console.log("Hi " + name)
@cindywu
cindywu / functionsAsArguments.js
Created November 28, 2020 03:41
passing functions as arguments javascript simplified
function printVariable(variable) {
console.log(variable)
}
function newfunc(name, callback) {
callback(name)
}
/* function callback(x) {
console.log("Hello " + x)
@cindywu
cindywu / Editor.js
Created October 13, 2020 22:50
Editor.js function componenet wip
function useForceUpdate() {
const [, setValue] = useState(0)
return () => setValue((value) => ++value)
}
export default function Editor(props) {
const {
post,
options,
onChange,
@cindywu
cindywu / ChangesIndicator.tsx
Created October 11, 2020 01:42
ChangesIndicator from js to function component using tsx
/* eslint-disable jsx-a11y/no-autofocus */
import React from 'react'
import { formatDistanceToNow } from 'date-fns'
interface Props {
isLoading: boolean
hasUnsavedChanges: boolean
isNewPost: boolean
lastSavedAtDate: any
}
@cindywu
cindywu / Editor.js
Created October 11, 2020 01:41
editor.js function component
import React, { Component, createRef, useRef, useEffect, useState } from 'react'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { commentPluginKey } from './editor-config/comments'
// import applyDevTools from 'prosemirror-dev-tools'
export default function Editor(props) {
const {
post,
options,