Skip to content

Instantly share code, notes, and snippets.

View jsoendermann's full-sized avatar

Jan Söndermann jsoendermann

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jsoendermann on github.
  • I am jsoendermann (https://keybase.io/jsoendermann) on keybase.
  • I have a public key whose fingerprint is 9AD4 1092 7FC9 294A 8F7C 0488 66C4 BA6A D452 476A

To claim this, I am signing this object:

@jsoendermann
jsoendermann / decoratorTest.ts
Created November 30, 2016 00:12
TypeScript decorator that changes method type signature
// tsconfig.json:
// {
// "compilerOptions": {
// "target": "es6",
// "experimentalDecorators": true
// }
// }
const decorator = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const originalMethod = descriptor.value;
@jsoendermann
jsoendermann / result.ts
Last active January 6, 2021 15:44
TypeScript Result type
interface IValue<T> {
type: 'value'
value: T
}
interface IError<E extends Error> {
type: 'error'
error: E
}
@jsoendermann
jsoendermann / cluster.js
Created March 21, 2017 08:26
Simple clustering
const EPSILON = 0.1
const cluster = (array, threshold) => {
for (const e of array) {
return array.filter(e_ => Math.abs(e - e_) < EPSILON).length / array.length >= threshold
}
}
if (
cluster([0, 0.0001, 0.01, 0.0, 9], 0.5) &&
@jsoendermann
jsoendermann / mongo.md
Last active April 24, 2017 05:58
Mongo styleguide

MongoDB Style Guide

General

  • Don't mix types. Do be conservative in what you write liberal in what you accept
  • Don't use the empty string or 0 for their falsiness. Do make non-casting, explicit comparisons

Enums

  • Don't use numbers, booleans or any other types to model enumerations. Do model them as uppercase string constants, e.g. "WAITING", "IN_PROGRESS" and "COMPLETED".
@jsoendermann
jsoendermann / sectionListGetItemLayout.jsx
Last active December 9, 2019 21:16
sectionListGetItemLayout
import sectionListGetItemLayout from 'react-native-section-list-get-item-layout'
class MyComponent extends React.Component {
constructor(props) {
super(props)
this.getItemLayout = sectionListGetItemLayout({
// The height of the row with rowData at the given sectionIndex and rowIndex
getItemHeight: (rowData, sectionIndex, rowIndex) => sectionIndex === 0 ? 100 : 50,
@jsoendermann
jsoendermann / rn-native-pro-cons.md
Last active July 10, 2017 03:05
React Native vs Native

React Native

+++ Our team has lots of experience with JavaScript + React

+++ Build once for both platforms

++ Much better developer experience (faster turnaround times)

+ Can update without having to go through the app store most of the time

@jsoendermann
jsoendermann / project-names.md
Last active August 11, 2017 04:40
Project Names
  • angry ant
  • bashful bee
  • cunning cod
  • dodgy dove
  • edgy eel
  • fidgety frog
  • gregarious giraffe
  • hapless hedgehog
  • inept impala
  • jovial jaguar
@jsoendermann
jsoendermann / oss-upload.sh
Created November 22, 2017 02:18
阿里云 Aliyun OSS curl upload 上传
RESOURCE="/${OSS_BUCKET_NAME}/${OBJECT_NAME}"
CONTENT_MD5=$(openssl dgst -md5 -binary "${FILEPATH}" | openssl enc -base64)
CONTENT_TYPE=$(file -ib "${FILEPATH}" |awk -F ";" '{print $1}')
DATE_VALUE="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`"
STRING_TO_SIGN="PUT\n${CONTENT_MD5}\n${CONTENT_TYPE}\n${DATE_VALUE}\n${RESOURCE}"
SIGNATURE=$(echo -e -n $STRING_TO_SIGN | openssl dgst -sha1 -binary -hmac $OSS_ACCESS_KEY_SECRET | openssl enc -base64)
URL="http://${OSS_BUCKET_NAME}.${OSS_REGION}.aliyuncs.com/${OBJECT_NAME}"
curl -i -q -X PUT -T "${FILEPATH}" \
-H "Host: ${OSS_BUCKET_NAME}.${OSS_REGION}.aliyuncs.com" \
-H "Date: ${DATE_VALUE}" \
@jsoendermann
jsoendermann / aliases.sh
Last active November 26, 2020 11:11
useful aliases
alias gs="git status -sb"
alias gd="git diff"
alias ga="git add"
alias gh="git checkout"
alias gc="git commit"
alias gcn="git commit --no-verify"
alias gca="git commit --amend --no-edit"
alias gp="git push"
alias gpl="git pull"
alias gpr="git pull --rebase"