This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extend | |
System.arraycopy(names, 0, extended, 0, names.length); | |
// difference | |
objArray.removeAll(objArray2); | |
// intersection | |
objArray.retainAll(objArray2); | |
// union | |
Set<String> set = new HashSet<String>(); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExceptionOperations{ | |
try | |
{ | |
//... | |
} | |
catch (ArithmeticException e) | |
{ | |
System.out.println(e.toString()); | |
} | |
catch (ArrayIndexOutOfBoundsException e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
#... |
OlderNewer