Skip to content

Instantly share code, notes, and snippets.

Neil Ding GingerBear

Block or report user

Report or block GingerBear

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View arr-filter-type-guard.ts
function notNullOrUndefined<T>(x: T | null | undefined): x is T {
return x !== null && x !== undefined;
}
const arr = [1, 2, null, undefined]; // (number | null | undefined)[]
const arrFiltered = arr.filter(notNullOrUndefined); // number[]
View sampleArray.js
function sampleArray(arr, num) {
if (arr.length <= num) {
return arr;
} else {
const every = Math.floor(arr.length / num);
const sampleIndex = Array(num)
.fill(0)
.map((_, i) => i * every);
// keep last element
@GingerBear
GingerBear / Dockerfile
Last active Apr 1, 2019
alpine node3 with python 3 and puppeteer ready
View Dockerfile
FROM node:10-alpine
# Installs Python 3
RUN apk add --no-cache python3 && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
View proxy_dev_server.js
const express = require('express');
const path = require('path');
const fs = require('fs');
const proxy = require('http-proxy-middleware');
const app = express();
const proxyConfig = require('./proxy-remote.conf.json');
const port = 4200;
const ngBuildPath = path.join(__dirname, 'dist/projectAbc');
const ngBuildIndex = fs
View proxy_dev_server.js
const express = require('express');
const path = require('path');
const fs = require('fs');
const proxy = require('http-proxy-middleware');
const app = express();
const proxyConfig = require('./proxy-remote.conf.json');
const port = 4200;
const ngBuildPath = path.join(__dirname, 'dist/projectAbc');
const ngBuildIndex = fs
View codepush_release.md
  • install appcenter cli https://github.com/Microsoft/appcenter-cli
  • appcenter login
  • update "name": "GNCUAT", in package.json
  • add "react-native": "0.0.0", to dependencies in package.json
  • appcenter codepush release-react -a Branding-Brand/GNCIOS -d Latest
View union_type_check.ts
type typeA = { a: string };
type typeB = { b: string };
type typeAorB = typeA | typeB;
// type check for union type
function isA(foo: typeA | typeB): foo is typeA {
return (<typeA>foo).a !== undefined;
}
// usage
@GingerBear
GingerBear / react-native-git-upgrade-workaround.md
Last active Mar 2, 2018
in case react-native-git-upgrade is not working
View react-native-git-upgrade-workaround.md
@GingerBear
GingerBear / react-native-start-with-link.js
Last active Aug 13, 2019
start react native bunlder with link
View react-native-start-with-link.js
You can’t perform that action at this time.