Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Kirill Novik kino6052

🏠
Working from home
View GitHub Profile
View least-squares-closed-form.py
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]
View index.tsx
StateSubject.subscribe((state) => render(<App state={state} />, rootElement));
View bluePhaseUpdate.ts
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
};
View reduce.ts
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 {
View RedPhaseTest.ts
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",
View InitialState.ts
const initialState: IState = {
input: "",
isInStockOnly: false,
products: [
{
id: "0",
category: "Sporting Goods",
price: "$49.99",
stocked: true,
name: "Football"
View EventWrapper.tsx
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) => {
View existence.ts
const is = (it, n = Symbol()) => (it ?? n) !== n;
const is = it => (it ?? null) !== null;
@kino6052
kino6052 / remove-all-branches.sh
Created Nov 30, 2020
Remove All Local Branches
View remove-all-branches.sh
git branch | grep -v "master" | xargs git branch -D
View formik-is-pristine.ts
const isPristine = (
fieldName: string | string[],
touched: FormikTouched<FormikValues>
) =>
[fieldName]
.flatMap((fieldName) => fieldName)
.every((fieldName) => !touched[fieldName]);