自适应一般是设定基准值,宽、高、字体大小都指定为基准值的百分比。当基准值改变时,页面元素、宽高也会按比例变化。 自适应宽度 不使用绝对宽度 网页宽度默认等于屏幕宽度。所以大部分时候只要不适用绝对宽度即可实现自适应宽度: 1 2 3 4 body: { width: 100%; // or width: auto; } 如果元素是图片,也可以使用 max-width 属性,参见responsive web design: image 1 2 3 4 img { max-width: 100%; height: auto; } 使用 media 这适用于需要针对不同的屏幕,显示不同的排版。利用 @media 的 css 规则,可实现根据一个或多个基于设备类型、具体特点和环境的媒体查询来应用样式。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* Media query */ @media screen and (min-width: 900px) { article { padding: 1rem 3rem; } } /* Nested media query */ @supports (display: flex) { @media screen and (min-width: 90
Read more »

参见 Search and destroy duplicate rows in PostgreSQL Find duplicates using group 1 2 3 4 5 6 7 8 9 SELECT firstname, lastname, count(*) FROM people GROUP BY firstname, lastname HAVING count(*) > 1; using partition 1 2 3 4 5 6 7 8 9 SELECT * FROM (SELECT *, count(*) OVER (PARTITION BY firstname, lastname ) AS count FROM people) tableWithCount WHERE tableWithCount.count > 1; Using not strict distinct 利用 not strict distinct DISTINCT ON 找到唯一的那些条,剩余的就是重复的,可以修改或删除 1 2 3 4 5 6 7 8 9 DELETE FROM people WHERE people.id NOT IN (SELECT id FROM ( SELECT
Read more »

java.io.ByteArrayOutputStream 这一般在用到字节流是会用到。 java performance tuning guide 这篇文章不建议在 performance-criticted 代码中使用 ByteArrayOutputStream: 1. 同步写入,效率低 ByteArrayOutputStream allows you to write anything to an internal expandable byte array and use that array as a single piece of output afterwards. Default buffer size is 32 bytes, so if you expect to write something longer, provide an explicit buffer size in the ByteArrayOutputStream(int) constructor 注: 1. ByteArrayOutputStream 内部是一个可变长度的 byte[](通过扩充实现可变)。它有个初始长度(默认 32),可以在 constructor 中指定. 2. ByteArrayOutputStream 是同步写入,比较影响效率 2. toByteA
Read more »

three reasons why we should not use inheritance in tests 大概意思是: 1. 很多测试里的继承用的不合适。测试也是代码,必须符合继承的原则。 The point of inheritance is to take advantage of polymorphic behavior NOT to reuse code, and people miss that, they see inheritance as a cheap way to add behavior to a class. When I design code I like to think about options. When I inherit, I reduce my options. I am now sub-class of that class and cannot be a sub-class of something else. I have permanently fixed my construction to that of the superclass, and I am at a mercy of the super-class changing APIs. My freedom to change is fixed at co
Read more »

gradle test configurations one sample config ways to improve performance of gradle build common used properties: * jvmArgs: jvm 参数。通常会配置堆栈大小,保证测试对内存的要求。 * '-Xms128m', '-Xmx1024m', '-XX:MaxMetaspaceSize=128m'。-Xms 是初始堆大小,-Xmx 是最大堆大小,-XX:MaxMetaspaceSize 是 class metadata 可占用的最大本地内存(默认是 unlimited)。具体 jvm 参数参考 java doc. * forkEvery: 每个 test process 里跑的 test classes 的最大个数。当次数达到限制后,会自动重启。这定义了一个测试线程什么时候回重启,与并发无关。默认是 0,即无最大限制,就是可以一直跑 * maxParalleForks: 能并发跑的最大 test processes 数目 * systemProperty: 系统属性 * environment:系统环境变量 * include: 具体执行的测试。可以通过这个配置不同的测试级别(单元测试、集成测试、functional 测试……)
Read more »

Synchronous vs multiprocessing vs multithreading vs async Concurrency vs Parralism. asyncio & threading can run multiple I/O operations at the same time. Async runs one block of code at a time while threading just one line of code at a time. With async, we have better control of when the execution is given to other block of code but we have to release the execution ourselves. * IO bound problems: use async if your libraries support it and if not, use threading. * CPU bound problems: use multi-processing. * None above is a problem:you are probably just fine with synchronous code. You may
Read more »

Problems? 1. manifest 是干什么用的? 2. 代码运行时,如何找到 dependency 的包 3. java -jar 时,classpath 指定? classpath classpath 指定的是 java 类所在的目录(包括当前项目的类、依赖的类等)。应该是当打 jar 包的时候,默认会加上当前目录(.)到 classpath,这样就包含了 jar 内部的类? Thin jar gradle lean This plugin depends on JavaPlugin and ApplicationPlugin. * for installDist, jars under install/$PROJECT_NAME$/lib/ * for distZip, jars under /lib/ inside package 1 2 3 4 5 6 7 8 9 10 11 plugins { id 'java' // Apply the application plugin to add support for building a CLI application. id 'application' id 'scala' id 'com.github.maiflai.scalatest' ve
Read more »

背景 1. 项目需要引入 local 第三方包 2. 该第三方包只有 window/linux license,而开发在 macos 3. 开发时,通过 gradle dependency compile files('path/to/thejar.jar') 来引入包 问题 运行时,报错误 java.lang.UnsatisfiedLinkError: no thejar in java.library.path 原因 引入 .dll 或 .so 失败造成。 solution 1. 把 thejar 加入到 path 中 ————— not work 2. 加入 path,并 loadLibrary ——————— not work 3. should work(配置 .dll 或 .so 路径): 1. 配置 PATH 2. 或 jar 包启动时,设置 ‘-Djava.library.path’ 有关 PATH, -classpath, java.library.path 的区别,再 google。java 在使用这三个 path 时: 1. PATH:用来寻找 java, javac 等 command 并执行 2. classpath:jvm 在执行时用来寻找 java class。classpath 一般指向 jar
Read more »

几个核心类 参见: * java api * 入门 - 介绍核心使用组件和最佳实践 SqlSessionFactory mybatis 应用以一个 sqlSessionFactory 实例为核心,即一个应用中有一个单例 SqlSessionFactory,所以数据库 session 都从这里获得。 SqlSessionFactory 可以通过 SqlSessionFactoryBuilder 获得,builder 负责从 xml 配置或 java configuration 类获得。xml (或相应的 java configuration 类) 配置了 datasource(数据库连接信息)、mappers 等信息 SqlSessionFactoryBuilder 它主要就是用来获取 SqlSessionFactory,可以从 xml 或 Java Configuration 类加载配置并构建。提供如下几种方式来获取(参见java api): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // 从 xml 获取,其中配置了 environment,datasource,mappers SqlSessionFactory build(InputStream inputStream); // 从 xml 获取,但当 xml 配置了多个 env
Read more »
0%