Skip to content

Instantly share code, notes, and snippets.

diaolizhi

Block or report user

Report or block diaolizhi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@diaolizhi
diaolizhi / Singleton.cs
Last active Oct 17, 2018
c# 一般情况下的单例模式
View Singleton.cs
class OnlyYou
{
//构造函数
private OnlyYou()
{
}
//注意类型是 OnlyYou,并且是静态的
private static OnlyYou obj = null;
@diaolizhi
diaolizhi / Form2.cs
Created Oct 17, 2018
c# 单例窗口及其关闭处理
View Form2.cs
public partial class Form2 : Form
{
//唯一实例
private static Form2 obj = null;
private Form2()
{
//初始化控件(自动生成)
InitializeComponent();
}
@diaolizhi
diaolizhi / close.cs
Created Oct 21, 2018
C# winform 关闭窗口前确认
View close.cs
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = (MessageBox.Show("Sure?",
"Exit",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes);
DialogResult result = MessageBox.Show("提示", "确定退出吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
@diaolizhi
diaolizhi / random.java
Last active Oct 22, 2018
Java 数组随机打乱顺序
View random.java
public static void shuffle(Object[] a) {
//判断数组 a 是否可以转为整型数组
validateNotNull(a);
int n = a.length;
for (int i = 0; i < n; i++) {
int r = i + uniform(n-i); // between i and n-1
Object temp = a[i];
a[i] = a[r];
a[r] = temp;
}
@diaolizhi
diaolizhi / timer.cs
Last active Oct 25, 2018
C# 定时回调委托
View timer.cs
public Form1()
{
//TimerCallback 是委托类型,可以关联一个形参为 Object 的函数
TimerCallback timerCallback = new TimerCallback(timeUpdate);
//Timer 每隔 1000ms 调用委托
System.Threading.Timer timer = new System.Threading.Timer(timerCallback, "", 0, 1000);
}
public void timeUpdate(Object obj)
@diaolizhi
diaolizhi / Activity.java
Created Oct 28, 2018
Android Intent 传递对象
View Activity.java
//
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, WizardOne.class);
intent.putExtra("setting", setting);
startActivityForResult(intent, 1);
}
});
@diaolizhi
diaolizhi / note.java
Created Oct 28, 2018
Android 跳转到一个 Activity 前清空 Activity 栈
View note.java
btnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentToFinish = new Intent(WizardThree.this, FinishActivity.class);
//重点是下面这一句
intentToFinish.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intentToFinish.putExtra("setting", setting);
startActivity(intentToFinish);
WizardThree.this.finish();
}
@diaolizhi
diaolizhi / SynchronizedDemo.java
Created Nov 13, 2018
Java synchronized 作用于普通方法、静态方法、方法块
View SynchronizedDemo.java
package chapter3;
/**
* @program: studythread2
* @description: synchronized Demo
* @author: diaolizhi
* @create: 2018-11-13 10:29
**/
public class SynchronizedDemo {
@diaolizhi
diaolizhi / LazySingleton.java
Created Nov 13, 2018
Java 懒汉式单例模式 - 线程安全
View LazySingleton.java
package chapter3;
/**
* @program: studythread2
* @description: 懒汉式单例模式
* @author: diaolizhi
* @create: 2018-11-13 12:39
**/
public class LazySingleton {
@diaolizhi
diaolizhi / 加解密工具类.java
Last active Nov 18, 2018
Java JWT 加密解密
View 加解密工具类.java
package com.diaolizhi.mybatisdemo.utils;
import com.diaolizhi.mybatisdemo.domain.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
You can’t perform that action at this time.