Installing Composer Globally


https://tecadmin.net/install-php-composer-on-ubuntu/


curl -sS https://getcomposer.org/installer | php

sudo mv composer.phar /usr/local/bin/composer

chmod +x /usr/local/bin/composer





页面布局 grid,flex,绝对定位,圣杯及双飞翼布局

grid,flex,绝对定位,圣杯及双飞翼布局

Get all files in a folder and sub-folders


function walkSync(currentDirPath, callback) {
  // attrib: https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j

  fs.readdirSync(currentDirPath).forEach(function (name) {
    var filePath = path.join(currentDirPath, name);
    var stat = fs.statSync(filePath);
    if (stat.isDirectory()) {
      if (hasChildDirectories(filePath)) {
        walkSync(filePath, callback);
      }
      callback(filePath, stat);
    }
  });
}

序列化

java.io.Serializable

Has Child Directories?

function hasChildDirectories(currentDirPath) {
  let value = false;
  fs.readdirSync(currentDirPath).forEach(function (name) {
    var filePath = path.join(currentDirPath, name);
    var stat = fs.statSync(filePath);
    if (stat.isDirectory()) {
      value = true;
    }
  });
  return value;
}

Install maven Fedora

sudo nano /etc/profile
Add these commands at the end of the text file

export M2_HOME=/opt/apache-maven-3.3.9

export M2=$M2_HOME/bin

export PATH=$M2:$PATH

Reload profile by typing source /etc/profile in command line

Restart the system

Verify M2 by typing echo $M2 in command line

Verify PATH by typing echo $PATH in command line. Check if there is maven directory in the PATH variable or not.
Check maven version by typing mvn -version in command line

ArrayLists

Episode 6
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {

        ArrayList<String> strings = new ArrayList<>(4); //Can add 4 elements without reallocation
        System.out.println(strings.size()); //Like .length()
        strings.add("Vehicle"); //Add elements
        strings.add("Dolphin");
        strings.add("Jordan Peterson");
        strings.add("Booty");
        strings.add(1, "New Dolphin"); //Choose WHERE to put the elements
        System.out.println(strings.size());

        //Print out the contents of the array list
        System.out.println(strings);

        //Remove elements too
        strings.remove("Jordan Peterson"); //Remove it by its value/object
        strings.remove(3); //Remove by index
        System.out.println(strings);

        //Set capacity equal to the number of elements currently in the arraylist
        strings.trimToSize();

        //Convert an arraylist to a regular array
        Ar

Recibir un parametro por post en Laravel

function reciboPostDelFormulario(Request $request) {
  $nombre=$request->input("nombre");
}

En la vista supongamos que teníamos
<input type="text" name="nombre">

sleep

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Printf("Current Unix Time: %v\n", time.Now().Unix())

    time.Sleep(2 * time.Second)

    fmt.Printf("Current Unix Time: %v\n", time.Now().Unix())
}

Useful SourceTree Commands

Adds your ssh key to the keychain
cd ~/.ssh/; ssh-add

Crear un nuevo controlador en Laravel, dentro de una subcarpeta

Copiado de [https://laracasts.com/discuss/channels/laravel/create-controller-inside-a-subfolder?page=1]
php artisan make:controller frontend/SomeController

Usar la clase Db en Laravel para hacer consultas a la base de datos

Para poder realizar consultas a la base de datos, mediante la clase Db en Laravel, se necesita hacer el siguiente include
use Illuminate\Support\Facades\DB;

如何在业务层中添加Redis缓存

@Service
public class ContentServiceImpl implements ContentService {

	@Autowired
	private JedisClient client;
	
	@Autowired
	private TbContentMapper mapper;
	
	@Value("${CONTENT_KEY}")
	private String CONTENT_KEY;
	
	/* 同步缓存 */
	@Override
	public TaotaoResult saveContent(TbContent content) {
		//1.注入mapper
		
		//2.补全其他的属性
		content.setCreated(new Date());
		content.setUpdated(content.getCreated());
		//3.插入内容表中
		mapper.insertSelective(content);
		
		//当添加内容的时候,需要清空此内容所属的分类下的所有的缓存
		try {
			client.hdel(CONTENT_KEY, content.getCategoryId()+"");
			System.out.println("当插入时,清空缓存!!!!!!!!!!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return TaotaoResult.ok();
	}
    /* 从缓冲中获取 */
	@Override
	public List<TbContent> getContentListByCatId(Long categoryId) {
		
		//添加缓存不能影响正常的业务逻辑
		
		//判断 是否redis中有数据  如果有   直接从redis中获取数据 返回
		
		try {
			String jsonstr = client.hget(CONTENT_KEY, categoryId+"");//从redis数据库中获取内容分类下的所有的内容。
			//如果存在,

传统项目数据访问基类设计模板

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.ParameterizedType;
import java.util.Collections;
import java.util.List;

@Transactional // @Transactional可被继承,子类也有效
@SuppressWarnings("unchecked")
public class BaseDaoImpl<T> implements BaseDao<T> {

    @Autowired
    private SessionFactory sessionFactory;

    // 如何获取字节码类型
    private Class<T> clazz;

    public BaseDaoImpl() {
        // 通过构造器获取字节码类型
        ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
        this.clazz = (Class<T>) pt.getActualTypeArguments()[0];
    }

    public void add(T t) {
        getSession().save(t);
    }

    public void delete(Long id) {
        Object obj  = getSession().get(clazz, id);
        getSession().delete(obj);
    }

    public void edit(T t) {
        

JSON转换工具类

import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * JSON转换工具类
 */
public class JsonUtils {

    // 定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    /**
     * 将对象转换成json字符串。
     * <p>Title: pojoToJson</p>
     * <p>Description: </p>
     * @param data
     * @return
     */
    public static String objectToJson(Object data) {
    	try {
			String string = MAPPER.writeValueAsString(data);
			return string;
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    /**
     * 将json结果集转化为对象
     * 
     * @param jsonData json数据
     * @param clazz 对象中的object类型
     * @return
     */
    public static <T> T jsonToPojo(String jsonData, Class<T> beanType) {
        try {
            T t = MAPPER.readValue(jsonData, beanType);
            

页面分帧模板

经常使用的一个页面分帧模板
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

    <!-- 页面分帧 -->
    <frameset rows="80,*">
        <frame name="top" src="#"></frame>
        <frameset cols="220,*">
            <frame name="menu" src="#"></frame>
            <frame name="main" src="#"></frame>
        </frameset>
    </frameset>

</html>