Skip to content

Instantly share code, notes, and snippets.

Avatar
🍑
be sweet

Suyan suyanhanx

🍑
be sweet
View GitHub Profile
@buhichan
buhichan / bubu-form-antd.tsx
Last active Dec 30, 2020
model (rxjs) based form
View bubu-form-antd.tsx
import { Form, Col, Row, Button } from "antd"
import { FormItemProps } from "antd/lib/form"
import { useObservables } from "./use-observables"
import * as React from "react"
import { AbstractControl, ValidationInfo, FormControls, FormControlList } from "./model"
import { CloseOutlined, PlusOutlined, MinusOutlined } from "@ant-design/icons"
type FormItemRenderChildren<T, Meta> = (inputProps: { value?: T; onChange?: (v: T) => void }, behavior: Meta | null, err: ValidationInfo) => React.ReactNode
export function FormItem<T, Meta>({
@buhichan
buhichan / typescript-di.tsx
Last active Oct 19, 2020
A typescript DI solution with no need of reflect-metadata (and can also need no decorators, if you prefer it)
View typescript-di.tsx
//Idea is borrowed from https://github.com/gnaeus/react-ioc
//Differences are:
//1. Does not require reflect-metadata
//2. Has an additional "useProvider" method
import * as React from "react"
export interface Disposable {
dispose?(): void
}
@Treeki
Treeki / TurnipPrices.cpp
Last active Nov 21, 2021
AC:NH turnip price calculator
View TurnipPrices.cpp
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from https://github.com/simontime/Resead
namespace sead
{
class Random
{
View quickSort.js
// 2018.5.11更新: 减少了swap
function qSort(compare) {
var swap = (p1, p2) => {
var tmp = this[p1];
this[p1] = this[p2];
this[p2] = tmp;
}
var sortRange = (start, end) => {
var midValue = this[start];
var p1 = start + 1, p2 = end - 1;
@dahjelle
dahjelle / pre-commit.sh
Created Jul 13, 2016
Pre-commit hook for eslint, linting *only* staged changes.
View pre-commit.sh
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
@linhmtran168
linhmtran168 / pre-commit-eslint
Last active Sep 20, 2021
Pre-commit hook to check for Javascript using ESLint
View pre-commit-eslint
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
@dahlia
dahlia / lisp.rb
Created Sep 2, 2010
30 minutes Lisp in Ruby
View lisp.rb
# 30 minutes Lisp in Ruby
# Hong Minhee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,