Skip to content

Instantly share code, notes, and snippets.

View mirinzhang's full-sized avatar
🎯
Focusing

mirinzhang mirinzhang

🎯
Focusing
View GitHub Profile
@mirinzhang
mirinzhang / git-ssh-error-fix.sh
Created January 20, 2024 08:31 — forked from Tamal/git-ssh-error-fix.sh
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
@mirinzhang
mirinzhang / getDistanceByLatLng.ts
Created December 11, 2020 11:23
根据经纬度计算距离
function rad(d: number): number {
return (d * Math.PI) / 180;
}
function getDistanceByLatLng(lat1, lng1, lat2, lng2): number {
const EARTH_RADIUS = 6378137;
const r1 = rad(lat1);
const r2 = rad(lat2);
const a = r1 - r2;
const b = rad(lng1) - rad(lng2);
var noop = function(){};
var errorHandler = {
callback: null,
init: function (callback) {
errorHandler.callback = callback || noop;
window.onerror = errorHandler.script;
window.addEventListener('error', errorHandler.source, true);
window.addEventListener('unhandledrejection', errorHandler.promise, true);
@mirinzhang
mirinzhang / InViewPort.js
Created October 16, 2018 10:06
Check React-native Components InViewport
/**
* @File 检查元素是否在视口中
* @Author: yabingzyb.zhang
* @Date: 2018-10-16 15:45:13
* @Last Modified by: yabingzyb.zhang
* @Last Modified time: 2018-10-16 17:43:12
*/
import React, { Component, PropTypes } from 'react';
import { View, Dimensions } from 'react-native';
@mirinzhang
mirinzhang / queryString.js
Last active September 7, 2018 10:49
~ Parse a query string into an object and get a query param by name
const urlQuery = {
getAll(url) {
if(!url) {
return {};
}
const regx = /([^?=&]+)=([^&]*)?/g,
result = {};
url.replace(regx, (_, $1, $2) => result[$1] = decodeURIComponent($2 || ''));
@mirinzhang
mirinzhang / queryString.js
Created September 7, 2018 10:40
1.Parse a query string into an object
const urlQuery = {
getAll(url) {
if(!url) {
return {};
}
const regx = /([^?=&]+)=([^&]*)?/g,
result = {};
url.replace(regx, (_, $1, $2) => result[$1] = decodeURIComponent($2 || ''));
@mirinzhang
mirinzhang / LICENCE SUBLIME TEXT
Created June 26, 2018 06:15
Sublime Text 3 Serial key build is 3176
## Sublime Text 3 Serial key build is 3176
> * Added these lines into /etc/hosts
127.0.0.1 www.sublimetext.com
127.0.0.1 license.sublimehq.com
> * Used the license key
----- BEGIN LICENSE -----
@mirinzhang
mirinzhang / templateReplacer.js
Last active August 23, 2018 05:03
简化版模板字符串替换函数
/**
* 简化版模板字符串替换函数
* @param {string} str - 替换目标
* @param {object} replacer - 替换值集合
* @param {string} prefix - 替换字符左边界
* @param {string} suffix - 替换字符右边界
*/
const templateReplacer = (
str = '',
replacer = {},
@mirinzhang
mirinzhang / weekUtils.js
Last active April 8, 2018 06:59
周次计算
export const weekUtils = {
ONE_DAY: 86400000,
defaultWeekDays: [1, 2, 3, 4, 5, 6, 7],
/**
* 根据周开始星期重排周次顺序
* @params startDay
*/
sortWeekDays(startDay = 1) {
// 存在并且无法转为int类型时返回默认周次
if (startDay && isNaN(parseInt(startDay))) {
@mirinzhang
mirinzhang / openOrDownloadApp.js
Last active March 5, 2018 09:57
使用Js打开或者下载App
/**
* @param microLink 应用宝微下载链接
* @param schemeUrl 需要打开的schemeUrl
* @param downloadUrl App通用下载地址
*/
function openOrDownloadApp(microLink, schemeUrl, downloadUrl) {
// 收集设备信息
var deviceInfo = {
userAgent: navigator.userAgent.toLowerCase(),
isAndroid: !!navigator.userAgent.match(/android/ig),