ziggle

Hail Hydra


  • Home

  • Archives

  • Search

sql

Posted on 2017-12-23

sql 执行顺序

from -> where -> group by -> having -> select -> order by
select子句可以识别 别名

  • 使用cast函数转换数据类型

    1
    2
    SELECT name + CAST(gender as VARCHAR(10) ) ,age
    FROM dbo.student
  • 使用* 查询结果

    1
    2
    3
    select bookname ,quantity,book_price ,quantity*book_price as total_price
    from bookitem
    order by bookname
  • 使用case进行条件查询

    1
    2
    3
    4
    5
    6
    7
    8
    9
    select name,time,redit=
    case
    when time>=40 then 5
    when time>=30 then 4
    when time>=20 then 3
    else 2
    end
    from course
    order by redit

sql函数

字符串运算符

1
2
3
ASCII,CHAR,LOWER,UPPER,LTRIM,RTRIM,
LEFT,RIGHT,SUBSTRING,CHARINDEX,
REPLICATE,REVERSE,REPLACE
  • 将结果转成大写

    1
    2
    select upper(bookname) as name ,quantity,book_price
    from bookitem
  • 去空格

    1
    2
    select rtrim(name) + rtrim(dname) as info ,age
    from teacher

算术运算符 ABA,SIGN(调试参数的正负号),CEILING(最大),FLOOR
ROUND(四舍五入),COS,PI,RAND(0-1 之间浮点数)

1
select rand()

时间函数

DAY,MONTH,YEAR,DATEADD,DATEDIFF,DATENAME,DATEPART,GETDATE
-CONVERT 函数转换日期时间

1
2
3
CONVERT (data_type [(length), expression,style)

select CONVERT(VARCHAR ,GETDATE(),8) AS now_time

Read more »

vimdiff

Posted on 2017-12-22

git 全局配置位置

文件内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = ziggle
email = muyue1125@gmail.com
# [https]
# proxy = https://127.0.0.1:8087
# [http]
# proxy = http://127.0.0.1:8087
[merge]
tool = vimdiff #vim diff tools

配置git diff 工具

git config –global merge.tool

使用vim diff

git mergetool

位置 含义 代指
↖ local 文件 LOCAL / LO
↑ base 基部文件 nil
↗ remote 远程文件 REMOTE /RE
↓ 显示merge的内容 nil

命令

1
2
3
4
5
6
[c  :转到上一个冲突
]a :转到下一个冲突
:-qa :全部退出vim

:diffget LOCAL 接受本地修改
:diffget REMOTE 接受远程修改
  • 使用:buffes 确定4个窗口编号

hooktest

Posted on 2017-12-15

deploy

node webhook script
通过GitHub webhook 同步博客

1
2
3
4
5
6
7
8
9
10
var http = require('http');
var exec = require('child_process').exec;

var server = http.createClient((req,res)=>{
if(req.url==='webhooks/push'){
exec("")
console.log(123);
}
});
server.listen(4000)

java-basic

Posted on 2017-12-15

Class.forName() 返回一个类JVM会加载制定的类,并执行类的静态代码段

A a = (A)Class.forName(“pacage.A”).newInstance();
A a = new A()
通过包名和类名,实例对象

String className = readfromXMLConfig;
class c = Class.forName(className);
factory = (Exampleinterface)c.newInstence();

使用newInstance() 要保证:

  • 类已经加载
  • 类已经连接

使用Class类的静态方法forName 完成这两步

  • newInstance(): 弱类型,低效率,只能调用无参构造。
  • new: 强类型,相对高效,能调用任何public构造。
  • Class.forName(“”)返回的是类。
  • Class.forName(“”).newInstance()返回的是object 。

    ReentrantLock

    ReentrantLock是一个基于AQS的可重入的互斥锁,
    公平锁将确保等待时间最长的线程优先获取锁,将会使整体的吞吐量下降
    非公平锁将不能确定哪一个线程将获取锁,可能会导致某些线程饥饿。
1
2
3
4
5
6
7
8
9
10
11
12
13
public class ReentrantLockTest {
private final ReentrantLock lock = new ReentrantLock();
// ...

public void doSomething() {
lock.lock(); // block until condition holds
try {
// ... method body
} finally {
lock.unlock();
}
}
}

java 静态代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyDemo {
public static void main(String[] args) {

//1.创建委托对象
AbsSubject real = new RealSub();

//2.创建调用处理器对象
ProxyHandler handler = new ProxyHandler(real);

//3.动态生成代理对象
AbsSubject proxySub = (AbsSubject)Proxy.newProxyInstance(real.getClass().getClassLoader(),
real.getClass().getInterfaces(), handler);

//4.通过代理对象调用方法
proxySub.doJob();
proxySub.sum(3, 9);
int m = proxySub.multiply(3, 7);
System.out.println("multiply result is:"+m);
}
}

//被代理类的接口
interface AbsSubject {
void doJob();
void sum(int a, int b);
int multiply(int a, int b);
}

//实际的被代理类
class RealSub implements AbsSubject {

@Override
public void doJob() {
// TODO Auto-generated method stub
System.out.println("i am doing something");
}

@Override
public void sum(int a, int b) {
System.out.println(a+" + "+b+" = "+(a+b));
}

@Override
public int multiply(int a, int b) {
// TODO Auto-generated method stub
System.out.println(a+" * "+ b);
return a*b;
}

}

//动态代理的内部实现,调用处理器类,即实现 InvocationHandler 接口
//这个类的目的是指定运行时将生成的代理类需要完成的具体任务(包括Preprocess和Postprocess)
//即代理类调用任何方法都会经过这个调用处理器类
class ProxyHandler implements InvocationHandler {
private Object realSub;

public ProxyHandler(Object object) {
realSub = object;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("before");
Object res = method.invoke(realSub, args);
System.out.println("after");
return res;
}
}
Read more »

RedisTemplate

Posted on 2017-12-15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.ziggle.fan.service;

import com.google.common.util.concurrent.RateLimiter;
import io.lettuce.core.RedisCommandTimeoutException;
import io.lettuce.core.RedisConnectionException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.QueryTimeoutException;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
* redis 消息订阅
*
* @author: wp
* @date: 2019-03-13 14:31
*/

@Slf4j
@Service
public class RedisMessageSubscriber implements MessageListener {

private final StringRedisTemplate stringRedisTemplate;
private final RateLimiter rateLimiter;

public RedisMessageSubscriber(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
this.rateLimiter = RateLimiter.create(1);
}

@Override
public void onMessage(Message message, byte[] pattern) {
log.info("Received >> " + message + ", " + Thread.currentThread().getName());
}

private ExecutorService executorService = Executors.newSingleThreadExecutor(r -> {
Thread thread = new Thread(r);
thread.setName("insert-contact-th");
thread.setDaemon(true);
return thread;
});
private AtomicInteger flag = new AtomicInteger(0);

@PreDestroy
private void destroy() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
flag.getAndAdd(1);
}
});
if (!executorService.isShutdown()) {
executorService.shutdown();
}
}

// @PostConstruct
public void init() {
RateLimiter errorRate = RateLimiter.create(1);
executorService
.submit(() -> {
for (; ; ) {
if (flag.get() != 0) {
break;
}
try {
// todo bug
String key = stringRedisTemplate.opsForList().leftPop("key", 3, TimeUnit.SECONDS);

if (key != null) {
log.warn(key);
rateLimiter.acquire();
}
log.info("nothing.... ");
} catch (Exception e) {
errorRate.acquire();
if (!(e instanceof RedisCommandTimeoutException || e instanceof QueryTimeoutException)) {
log.error(e.getMessage(), e);
} else {
//ignore
}
}
}
});
}
}
Read more »
1…19202122
ziggle

ziggle

Hail Hydra !

110 posts
45 tags
RSS
GitHub
© 2021 ziggle
Powered by Hexo
|
Hail Hydra—