Skip to content

Instantly share code, notes, and snippets.

@taichi
taichi / .golangci.yml
Last active May 7, 2024 07:29
ロギングライブラリのあり方については別途要検討。zapやzerologを使うならファクトリ関数だけを置くようにした方がいいかも。
linters-settings: # 設定のデフォルト値は、https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml で確認できる
depguard: # packagesに宣言されているモジュールの取り扱いに関するルール。ブラックリスト形式で使っているので、列挙したものを使うとエラーになる。
list-type: blacklist
packages:
- golang.org/x/xerrors # go 1.13で必要な機能はすべてerrorsに取り込まれたので使わない
- github.com/rs/zerolog # ログ出力用のライブラリはプロジェクト内部に作ったファクトリ関数経由で使うため
packages-with-error-message:
- golang.org/x/xerrors: "エラー処理は標準のerrorsを使って下さい。スタックトレースが必要な場合のみpkg/errorsを使って下さい"
- github.com/rs/zerolog: "ログ出力は example.com/myproject/logger#Newから利用して下さい"
dupl: # コードのコピペを検出するルール。 閾値のトークン数を越えるものをエラーにする
@zhiqiang21
zhiqiang21 / 移动端H5图片压缩上传.md
Created March 21, 2017 03:34
移动端h5图片压缩上传

移动端H5图片压缩上传

大体的思路是,部分API的兼容性请参照caniuse

  1. 利用FileReader,读取blob对象,或者是file对象,将图片转化为data uri的形式。
  2. 使用canvas,在页面上新建一个画布,利用canvas提供的API,将图片画入这个画布当中。
  3. 利用canvas.toDataURL(),进行图片的压缩,得到图片的data uri的值
  4. 上传文件。

步骤1当中,在进行图片压缩前,还是对图片大小做了判断的,如果图片大小大于200KB时,是直接进行图片上传,不进行图片的压缩,如果图片的大小是大于200KB,则是先进行图片的压缩再上传:

@doozMen
doozMen / LocalNetworkAuthorization.swift
Created February 25, 2022 15:44
Uses bonjour networking to relialby check if user has granted local network access with async await as of iOS14
import Foundation
import Network
/// Uses bonjour networking to relialby check if user has granted local network access
/// How to use:
/// Add LocalNetworkAuthorization class to your project
/// Open .plist file and add "_bonjour._tcp", "_lnp._tcp.", as a values under "Bonjour services"
/// Call requestAuthorization() to trigger the prompt or get the authorization status if it already been approved/denied
/// about the author: https://stackoverflow.com/a/67758105/705761
@winny-
winny- / force-inet4-or-inet6.c
Last active May 7, 2024 07:20
Force IPv4 or IPv6 in applications such as Lynx
/*
force-inet4-or-inet6.c - hack to force applications to use IPv4 or IPv6 exclusively
compilation: cc -fPIC -shared -DUSE_INET4 -o force-inet4.so force-inet4-or-inet6.c
cc -fPIC -shared -DUSE_INET6 -o force-inet6.so force-inet4-or-inet6.c
usage: LD_PRELOAD=/path/to/library.so program args ...
This file is in the public domain.
*/
@wojteklu
wojteklu / clean_code.md
Last active May 7, 2024 07:19
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@SkyzohKey
SkyzohKey / EventSocket.js
Last active May 7, 2024 07:18
EventSocket.js - A JSON event based client-side websocket wrapper.
/**
* @class EventSocket - A JSON event based client-side websocket wrapper.
* @param {String} scheme - The websocket server address scheme, can be `ws`, `wss`, `http`, `https`, whatever...
* @param {String} host - The websocket server ip address.
* @param {String} port - The websocket server port.
**/
function EventSocket (scheme, host, port) {
this.uri = [ scheme, '://', host, ':', port ].join('');
this.callbacks = {};
this.socket = null;
@y0ngb1n
y0ngb1n / docker-registry-mirrors.md
Last active May 7, 2024 07:17
国内的 Docker Hub 镜像加速器,由国内教育机构与各大云服务商提供的镜像加速服务 | Dockerized 实践 https://github.com/y0ngb1n/dockerized

Docker Hub 镜像加速器

国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务。

Dockerized 实践 https://github.com/y0ngb1n/dockerized

配置加速地址

Ubuntu 16.04+、Debian 8+、CentOS 7+

@kylehughes
kylehughes / TornRectangle.swift
Last active May 7, 2024 07:17
A rectangle shape for SwiftUI that can render any edge like a torn piece of paper.
// Copyright 2021 Kyle Hughes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@lukehutton
lukehutton / EnableSchUseStrongCrypto.ps1
Last active May 7, 2024 07:15
http://msdn.microsoft.com/en-us/library/windows/desktop/aa379810(v=vs.85).aspx HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto Instructs Schannel to disable known weak cryptographic algorithms, cipher suites, and SSL/TLS protocol versions that may be otherwise enabled for better interoperability.
New-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -name 'SchUseStrongCrypto' -value 1 -PropertyType 'DWord' -Force | Out-Null
@mrcunninghamz
mrcunninghamz / SelfSignedCert.md
Last active May 7, 2024 07:13
Creating a self signed certificate in a pfx format on a mac.

Create Self Signed Certificate using OpenSSL on a Mac

Introduction

Every now and then I need to create a self signed certificate in azure for something. In my particular case its Azure B2C. I am using a mac so its not simply just running something like

New-SelfSignedCertificate `
    -KeyExportPolicy Exportable `
    -Subject "CN=yourappname.yourtenant.onmicrosoft.com" `
 -KeyAlgorithm RSA `