Skip to content

Instantly share code, notes, and snippets.

Avatar
😎

Seyyed Morteza Moosavi smmoosavi

😎
View GitHub Profile
@smmoosavi
smmoosavi / svelte-routing.d.ts
Last active Jan 25, 2021
svelte-routing typings
View svelte-routing.d.ts
declare module 'svelte-routing' {
import { SvelteComponent, SvelteComponentTyped } from 'svelte';
interface LinkProps {
to: string;
replace?: boolean;
state?: {
[k in string | number]: unknown;
};
getProps?: (linkParams: GetPropsParams) => Record<string, any>;
View yarn global
{
"dependencies": {
"@jaebradley/fruit": "^1.0.20",
"@nrwl/cli": "^9.4.1",
"@persper/js-callgraph": "^1.3.2",
"@storybook/cli": "^5.3.17",
"@typescript-eslint/eslint-plugin": "^2.13.0",
"cloc": "^2.5.1",
"commitizen": "^4.0.3",
"conventional-changelog-cli": "^2.0.23",
View utils.ts
type ComponentProps<C> = C extends React.ComponentType<infer P> ? P : any;
@smmoosavi
smmoosavi / jalaaliUtils.js
Created Mar 15, 2018
material-ui-pickers-jalaali-utils
View jalaaliUtils.js
import jMoment from 'moment-jalaali'
import { toPersian } from './toPersian'
export default class jalaaliUtils {
static toJMoment (date) {
return jMoment(date ? date.clone() : undefined)
}
static parse (value, format) {
return jMoment(value, format)
@smmoosavi
smmoosavi / README.md
Last active Nov 21, 2017
list of questions for publishing npm package
View README.md

what packages we need?

eslint

  • eslint
  • eslint-config-airbnb
  • eslint-plugin-import
  • eslint-plugin-jsx-a11y
  • eslint-plugin-react

.eslintrc

@smmoosavi
smmoosavi / code.py
Last active Dec 27, 2017
graphql example
View code.py
@classmethod
def mutate_and_get_payload(cls, input, context, info):
user = context.user
old_password = input.get('old_password')
new_password = input.get('new_password')
if user.has_usable_password():
if not user.check_password(old_password):
raise ResponseError(
"Invalid Password",
@smmoosavi
smmoosavi / Exceptions.py
Created May 26, 2017
graphene-django custom error and better error handling
View Exceptions.py
class ResponseError(Exception):
def __init__(self, message, code=None, params=None):
super().__init__(message)
self.message = str(message)
self.code = code
self.params = params
@smmoosavi
smmoosavi / .gitconfig
Last active Jun 25, 2018
my git alias
View .gitconfig
[alias]
lg = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr %an)%Creset' --abbrev-commit --date=relative
glg = !git lg --graph
tree = log --graph --decorate --pretty=oneline --abbrev-commit
tr = !LESS="-RFX" git tree
unstage = reset HEAD
last = log -1 HEAD
visual = !gitk
st = status
uncommit = reset --soft HEAD^
@smmoosavi
smmoosavi / fields.py
Created Mar 30, 2017
Array Form Field
View fields.py
from django.contrib.postgres.forms import SimpleArrayField, ValidationError, prefix_validation_error
class ArrayField(SimpleArrayField):
def prepare_value(self, value):
return [self.base_field.prepare_value(v) for v in value]
def to_python(self, value):
# see django/contrib/postgres/forms/array.py:37
if value:
items = value