Coder Social home page Coder Social logo

blog's People

Contributors

domliang avatar

blog's Issues

使用Let's Encrypt泛域名ssl证书埋坑记

安装acme.sh

wget -O -  https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1  sh
source .bashrc

颁发证书

# domain
acme.sh  --issue  -d example.com -d *.example.com --dns dns_ali --force --keylength ec-384
# --keylength ec-384 指的是使用ECDSA 证书 (384 Bits)

有关dnsapi可以点击这里查看

dns使用dns_ali 的同学请注意, 阿里云域名不支持RAM角色访问API请使用老的AccessKey进行配置

安装证书

mkdir *.example.com
acme.sh --install-cert -d *.example.com \
--cert-file ~/*.example.com/cert.pem \
--key-file ~/*.example.com/key.pem \
--fullchain-file ~/*.example.com/fullchain.pem \
--reloadcmd "systemctl reload nginx.service"

使用aws china的同学注意了, 由于aws**无法申请证书所以我们需要将我们的证书换上去, 需要注意的一点是证书链 key.pem填入密钥, cert.pem填入证书, 证书链中我们填的并不是fullchain.pem, 而是我们要从fullchain.pem 中去掉 cert.pem的其他部分, 否则会报错

更新证书

acme.sh  --renew -d  *.example.com  -d example.com --force --ecc
# --ecc 指定ECDSA证书

使用Egg.js和TypeScript开发web服务

$ npx egg-init --type=ts showcase
$ cd showcase && npm i
$ npm run dev

一些约束:

  • Egg 目前没有计划使用 TS 重写。
  • Egg 以及它对应的插件,会提供对应的 index.d.ts 文件方便开发者使用。
  • TypeScript 只是其中一种社区实践,我们通过工具链给予一定程度的支持。
  • TypeScript 最低要求:版本 2.8。

整体目录结构

showcase
├── app
│   ├── controller
│   │   └── home.ts
│   ├── service
│   │   └── news.ts
│   └── router.ts
├── config
│   ├── config.default.ts
│   ├── config.local.ts
│   ├── config.prod.ts
│   └── plugin.ts
├── test
│   └── **/*.test.ts
├── typings
│   └── **/*.d.ts
├── README.md
├── package.json
├── tsconfig.json
└── tslint.json

控制器(Controller)

// app/controller/home.ts
import { Controller } from 'egg';

export default class HomeController extends Controller {
  public async index() {
    const { ctx, service } = this;
    const page = ctx.query.page;
    const result = await service.news.list(page);
    await ctx.render('home.tpl', result);
  }
}

路由(Router)

// app/router.ts
import { Application } from 'egg';

export default (app: Application) => {
  const { router, controller } = app;
  router.get('/', controller.home.index);
};

服务(Service)

// app/service/news.ts
import { Service } from 'egg';

export default class NewsService extends Service {
  public async list(page?: number): Promise<NewsItem[]> {
    return [];
  }
}

export interface NewsItem {
  id: number;
  title: string;
}

中间件(Middleware)

import { Context } from 'egg';

// 这里是你自定义的中间件
export default function fooMiddleware(): any {
  return async (ctx: Context, next: () => Promise<any>) => {
    // 你可以获取 config 的配置:
    // const config = ctx.app.config;
    // config.xxx....
    await next();
  };
}

详情参见 https://eggjs.org/zh-cn/tutorials/typescript.html

Flutter 本地化l10n(多语言i18n)的支持

首先说一下要用到的库

主要用到3个库flutter_localizations intl intl_translation

dependencies:
  flutter_localizations:
    sdk: flutter
  intl: 0.15.7
dev_dependencies:
  intl_translation: 0.17.4

设置App

  return MaterialApp(
    onGenerateTitle: (BuildContext context) =>
        AppLocalizations.of(context).title,
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: routes.buildPage('login', null),
    localizationsDelegates: [
      // ... app-specific localization delegate[s] her
      AppLocalizationsDelegate(),
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
    ],
    supportedLocales: [
      // 支持语言设置
      const Locale('en', 'US'), // English
      const Locale('zh', 'CH'), // Chinese
      // ... other locales the app supports
    ],
    onGenerateRoute: (RouteSettings settings) {
      return MaterialPageRoute<Object>(builder: (BuildContext context) {
        return routes.buildPage(settings.name, settings.arguments);
      });
    },
  );

编写本地化类

Lib/localizations.dart

import 'package:flutter/material.dart';
// import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart';

import 'l10n/messages_all.dart';

class AppLocalizations {
  static Future<AppLocalizations> load(Locale locale) {
    final String name =
        locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
    final String localeName = Intl.canonicalizedLocale(name);
    return initializeMessages(localeName).then((_) {
      Intl.defaultLocale = localeName;
      print(
          'the local code of $localeName ${locale.countryCode.isEmpty} ${locale}');
      return AppLocalizations();
    });
  }

  static AppLocalizations of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations);
  }

  String get title {
    return Intl.message(
      'Hello World',
      name: 'title',
      desc: 'Title for the Demo application',
    );
  }
}

class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);

  @override
  Future<AppLocalizations> load(Locale locale) => AppLocalizations.load(locale);

  @override
  bool shouldReload(AppLocalizationsDelegate old) => false;
}

导出intl_messages.arb

导出命令

flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/localizations.dart

导出的文件 l10n/intl_messages.arb

{
  "@@last_modified": "2019-04-28T15:58:14.536252",
  "title": "Hello World",
  "@title": {
    "description": "Title for the Demo application",
    "type": "text",
    "placeholders": {}
  }
}

编写对应的 l10n/intl_[locale].arb

l10n/intl_en.arb

{
  "@@last_modified": "2019-04-28T15:58:14.536252",
  "title": "Hello World",
  "@title": {
    "description": "Title for the application",
    "type": "text",
    "placeholders": {}
  }
}

l10n/intl_zh.arb

{
  "@@last_modified": "2019-04-28T15:58:14.536252",
  "title": "你好世界",
  "@title": {
    "description": "Title for the application",
    "type": "text",
    "placeholders": {}
  }
}

arb 导出 dart 类

命令

flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/l10n \
   --no-use-deferred-loading lib/localizations.dart lib/l10n/intl_*.arb

使用

import 'localizations.dart';

...
AppLocalizations.of(context).title

更新 iOS app bundle

打开ios/Runner.xcworkspace找到Runner的Info.plist

添加一个key为Localizationsvalue为你支持的语言

最后

good luck

Flutter 使用 scoped_model 合并 Model 时 发现mixin_inherits_from_not_object error

错误内容

[Flutter/Dart] The class can’t be used as a mixin because it extends a class other than Object. Error [mixin_inherits_from_not_object]

解决方案:

# pubspec.yaml
analyzer:
  strong-mod: true
  language:
    enableSuperMixins: true
# analysis_options.yaml
analyzer:
  errors:
    mixin_inherits_from_not_object: ignore

参考资料

https://medium.com/@amandeepkochhar/flutter-dart-the-class-cant-be-used-as-a-mixin-because-it-extends-a-class-other-than-object-a53eb5f214b0

树莓派 Raspberry Pi 3B+ 安装 snappy ubuntu 系统 ap 设置

新年收到的礼物

2019年1月1日收到一个新年礼物, 打开发现是一个树莓派. 真的很开心收到这个礼物, 但是这也意味着我要分一部分时间去找个这个小可爱了

装系统

到手第一件事, 就是给他装一个系统, 我收到的树莓派是 Raspberry Pi 3B+, 我看到官网上支持一直想尝试的Snappy Ubuntu Core于是我就开始了土坑模式.

安装并开启ap

按照文档把系统装好后发现, 换了网络后每次用本 ssh 链接 树莓派很麻烦, 由于3B+自带网卡所以起个ap不是啥难事(无外接硬件), 所以上网搜了一下还真的很简单

snap set wifi-ap automatic-setup.disable=true

如果没有安装wifi-ap会出现如下错误

Command "wifi-ap" not found, but can be installed with:

sudo snap install wifi-ap

See 'snap info <snap name>' for additional versions.

好吧缺少包 执行安装

sudo snap install wifi-ap

wifi-ap 21 from Canonical✓ installed

设置打开

sudo snap set wifi-ap automatic-setup.disable=true

交互式设置更多

sudo wifi-ap.setup-wizard

have fun ❤️

flutter 安卓环境配置问题 ✗ Android license status unknown.

配置完flutter之后执行

flutter doctor -v

执行结果是

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
    • Flutter version 1.0.0 at /Users/Dom/development/flutter
    • Framework revision 5391447fae (2 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /usr/local/Cellar/android-sdk/24.4.1_1
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.2.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.30.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected device (1 available)
    • DOM • 00008020-000D78960A82002E • ios • iOS 12.1

! Doctor found issues in 1 category.

WFT

✗ Android license status unknown.

是什么鬼

然后我就执行了

flutter doctor --android-licenses

同意licenses就好了

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
    • Flutter version 1.0.0 at /Users/Dom/development/flutter
    • Framework revision 5391447fae (2 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /usr/local/Cellar/android-sdk/24.4.1_1
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.2.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.30.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected device (1 available)
    • DOM • 00008020-000D78960A82002E • ios • iOS 12.1

• No issues found!

enjoy it ❤️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.