Skip to content

Instantly share code, notes, and snippets.

View jingyuexing's full-sized avatar
:octocat:
Boom

jingyuexing jingyuexing

:octocat:
Boom
View GitHub Profile
@jingyuexing
jingyuexing / ReadJSON.js
Created November 11, 2019 21:19
Read JSON file in nodejs
View ReadJSON.js
const fs = require("fs")
function ReadJSON(fileName=''){
var strList = fileName.split(".");
var string;
if(strList[strList.length-1].toLowerCase()=="json"){
string = fs.readFileSync(fileName);
}
return JSON.parse(string.toString())
}
@jingyuexing
jingyuexing / ReadJSON.py
Last active November 11, 2019 21:20
Read JSON file in Python
View ReadJSON.py
def readJSON(fileName=""):
import json
if fileName!='':
strList = fileName.split(".")
if strList[len(strList)-1].lower() == "json":
with open(fileName,mode='r',encoding="utf-8") as file:
return json.loads(file.read())
View IP.py
class IP:
ip:str
integer:int
def __init__(self,address=0):
if isinstance(address,int):
self.integer = address
self.ip = self.toString(address)
if isinstance(address,str):
self.ip = address
self.integer = self.toInteger(address)
View IPv4Convert.js
/**
* [IParser description]
* @param {string} ip IPv4 string
*/
function IParser(ip) {
let ipValue = 0
let temp = ip.split(".");
for (let i = 0; i < temp.length; i++) {
ipValue += Number(temp[i]) * Math.pow(0x100, 3 - i)
}
View SQLBuilder.py
from typing import Optional,Any,Literal
def object_item(target:object):
for key in target.__dict__:
value = getattr(target,key)
if(key.find("__") == -1):
yield (key,value)
def type_convert(var:Any):
SQLType = {
"str":"varchar",
"int":"int",