Skip to content

Instantly share code, notes, and snippets.

View XDo0's full-sized avatar
🪐
Working from home

D0nnie XDo0

🪐
Working from home
View GitHub Profile
@XDo0
XDo0 / Traversal of Java hashmap value
Created April 25, 2021 08:27
Traversal of Java hashmap value
Iterator< Map.Entry< Integer,String>> it = hashmap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry< Integer,String> entry = it.next();
// entry.getKey()
// entry.getValue()
System.out.print(entry.getValue());
}
@XDo0
XDo0 / get_files_in_the_directory.py
Last active July 21, 2022 12:45
python:get files in the directory which includes several subdirectories
# Only one-level subfolders are supported
import os
def get_files(DIR):
file_list=list()
for sub_dir in os.listdir(DIR):
if os.isdir(sub_dir):
for file in os.listdir(os.path.join(DIR,sub_dir)):
file_list.append(file)
return file_list
@XDo0
XDo0 / addtwodimdict
Created July 14, 2021 02:49
Add to 2-D dict Python
def addtwodimdict(thedict, key_a, key_b, val):
if key_a in adic:
thedict[key_a].update({key_b: val})
else:
thedict.update({key_a:{key_b: val}})
@XDo0
XDo0 / TypeConvert.java
Last active November 28, 2021 13:02
Java Type Conversion
//string 2 list
List<String> l=Arrays.asList(s.split(""));
// array 2 list(except 8 basic types),reference type
List<T> l=Arrays.asList(array);
//8 basic types arrays 2 list, such as Integer
List list=new ArrayList();
double array[]={12,223,234};
for(int i=0;i<array.length;i++){
@XDo0
XDo0 / Array Extend & Set operation.java
Last active September 10, 2022 03:36
Java Array Operations
// extend
System.arraycopy(names, 0, extended, 0, names.length);
// difference
objArray.removeAll(objArray2);
// intersection
objArray.retainAll(objArray2);
// union
Set<String> set = new HashSet<String>();
...
@XDo0
XDo0 / CreateTempFile&Modifiedtime.java
Last active November 25, 2021 01:27
Java File Operations
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
File temp = File.createTempFile("tmp", ".txt");
System.out.println("File Path: "+temp.getAbsolutePath());
Date filetime = new Date(temp.lastModified());
System.out.println(filetime.toString());
System.out.println(fileToChange.setLastModified(System.currentTimeMillis()));
@XDo0
XDo0 / ExceptionOperations.java
Created November 28, 2021 08:39
Java Exception
class ExceptionOperations{
try
{
//...
}
catch (ArithmeticException e)
{
System.out.println(e.toString());
}
catch (ArrayIndexOutOfBoundsException e)
@XDo0
XDo0 / MyBase64.java
Last active December 27, 2021 07:49
java Base64 method
import java.util.Base64;
public class MyBase64{
public static String base64(String str,int mode) throws InvalidParameterException{
if (mode == 1) {
byte[] bytes = str.getBytes();
//Base64 加密
String encoded = Base64.getEncoder().encodeToString(bytes);
return encoded;
@XDo0
XDo0 / run_cmd1.py
Last active January 11, 2022 07:38
2 funcs to run cmd import subprocess (python)
from subprocess import PIPE,Popen
import logging
logger = logging.getLogger('dev.utils')
logger.setLevel(logging.WARNING)
logging.basicConfig(filename='./log/'+datetime.now().strftime(f'{__file__}_%H_%M_%d_%m_%Y.log'),
filemode='a',
level=logging.WARNING,
format='%(asctime)s %(message)s',
datefmt='%d %b %Y %H:%M:%S')
@XDo0
XDo0 / crawl_url.py
Created December 31, 2021 02:21
python request a url & Beautifulsoup spider
from bs4 import BeautifulSoup,SoupStrainer
import requests
def crawl_url(keyword):
url=f"https://www.google.com/search?q={keyword}"
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
all_tags=soup.find_all("div",attrs={"data-version-added":True})
# all_catas=soup.find_all(class_="devsite-nav-text")
#...