Skip to content

Instantly share code, notes, and snippets.

View kino6052's full-sized avatar
🏠
Working from home

Kirill Novik kino6052

🏠
Working from home
View GitHub Profile
@kino6052
kino6052 / formik-is-pristine.ts
Created November 20, 2020 19:19
Formik isPristine
const isPristine = (
fieldName: string | string[],
touched: FormikTouched<FormikValues>
) =>
[fieldName]
.flatMap((fieldName) => fieldName)
.every((fieldName) => !touched[fieldName]);
@kino6052
kino6052 / remove-all-branches.sh
Created November 30, 2020 17:37
Remove All Local Branches
git branch | grep -v "master" | xargs git branch -D
@kino6052
kino6052 / existence.ts
Last active December 8, 2020 16:34
Existence
const is = (it, n = Symbol()) => (it ?? n) !== n;
const is = it => (it ?? null) !== null;
import React from "react";
import { Subject } from "rxjs";
export type EventType = "click" | "change" | "focus";
export type Id = string;
export type IEvent = [EventType, Id, string | undefined];
export const EventSubject = new Subject<IEvent>();
export const EventWrapper: React.FC<{ id: string }> = (props) => {
const initialState: IState = {
input: "",
isInStockOnly: false,
products: [
{
id: "0",
category: "Sporting Goods",
price: "$49.99",
stocked: true,
name: "Football"
expect(reduce(['change', 'input-01', 'ball'], initialState)).toEqual({
input: "ball",
isInStockOnly: false,
products: [
{
id: "0",
category: "Sporting Goods",
price: "$49.99",
stocked: true,
name: "Football",
@kino6052
kino6052 / reduce.ts
Last active February 28, 2021 19:11
const reduce = (
event: IEvent,
state: typeof initialState
): typeof initialState => {
if (event[0] === "change" && event[1] === "input-01") {
const value = event[2];
const filteredProducts = state.products
.filter(({ name }) => name.toLowerCase().includes(value.toLowerCase()))
.map(({ id }) => id);
return {
const filterProducts = (event: IEvent, state: IState) => {
const value = event[2] || "";
const filteredProducts = state.products
.filter(({ name }) => name.toLowerCase().includes(value.toLowerCase()))
.map(({ id }) => id);
return {
...state,
input: value,
productsToDisplay: filteredProducts
};
StateSubject.subscribe((state) => render(<App state={state} />, rootElement));
x = np.array([[1, 1],[1, 2],[1, 3]]) ## must contain first column with one for theta bias
y = np.array([[4.5], [5.5], [8.5]])
_x = np.dot(x.T, x)
xI = np.linalg.inv(_x)
n = np.dot(xI,x.T)
theta = np.dot(n, y)
print(theta)
print(theta[0], theta[0][0])
print(x[0], x[0][0])
y1_hat = theta[0][0] + theta[1][0]*x[0][1]