def ipaddr_to_binary(ipaddr): """ A useful routine to convert a ipaddr string into a 32 bit long integer """ # from Greg Jorgensens python mailing list message q = ipaddr.split('.') return reduce(lambda a, b: long(a) * 256 + long(b), q)
def __init__(self, low, high, localtz): self.low = long(low) self.high = long(high) if (low == 0) and (high == 0): self.dt = 0 self.dtstr = "Not defined" self.unixtime = 0 return # Windows NT time is specified as the number of 100 nanosecond intervals since January 1, 1601. # UNIX time is specified as the number of seconds since January 1, 1970. # There are 134,774 days (or 11,644,473,600 seconds) between these dates. self.unixtime = self.get_unix_time() try: if localtz: self.dt = datetime.fromtimestamp(self.unixtime) else: self.dt = datetime.utcfromtimestamp(self.unixtime) # Pass isoformat a delimiter if you don't like the default "T". self.dtstr = self.dt.isoformat(' ') except: self.dt = 0 self.dtstr = "Invalid timestamp" self.unixtime = 0
def on_graphics_message(res): nonlocal frame_count, last_frame, last_1_frame_cost, last_2_frame_cost, last_3_frame_cost, time_count, mach_time_factor, last_time, \ jank_count, big_jank_count, jank_time_count, _list if type(res.plist) is InstrumentRPCParseError: for args in kperf_data(res.raw.get_selector()): time, code = args[0], args[7] if code == 830472984: if not last_frame: last_frame = long(time) else: this_frame_cost = (long(time) - last_frame) * mach_time_factor if all([last_3_frame_cost != 0, last_2_frame_cost != 0, last_1_frame_cost != 0]): if this_frame_cost > mean([last_3_frame_cost, last_2_frame_cost, last_1_frame_cost]) * 2 \ and this_frame_cost > MOVIE_FRAME_COST * NANO_SECOND * 2: jank_count += 1 jank_time_count += this_frame_cost if this_frame_cost > mean( [last_3_frame_cost, last_2_frame_cost, last_1_frame_cost]) * 3 \ and this_frame_cost > MOVIE_FRAME_COST * NANO_SECOND * 3: big_jank_count += 1 last_3_frame_cost, last_2_frame_cost, last_1_frame_cost = last_2_frame_cost, last_1_frame_cost, this_frame_cost time_count += this_frame_cost last_frame = long(time) frame_count += 1 if time_count > NANO_SECOND: print( f"{datetime.now().timestamp() - last_time} FPS: {frame_count / time_count * NANO_SECOND} jank: {jank_count} big_jank: {big_jank_count} stutter: {jank_time_count / time_count}") jank_count = 0 big_jank_count = 0 jank_time_count = 0 frame_count = 0 time_count = 0
def _refresh_token(self): """refresh access token""" headers = { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } params = { 'grant_type': 'client_credentials', 'client_secret': self.app_secret, 'client_id': self.app_id, } msg_body = urlencode(params, quote_via=quote_plus) try: response = _http.post(self.token_server, msg_body, headers) if response.status_code != 200: return False, 'http status code is {0} in get access token'.format( response.status_code) """ json string to directory """ response_body = json.loads(response.text) self.access_token = response_body.get('access_token') self.token_expired_time = long(round(time.time() * 1000)) + ( long(response_body.get('expires_in')) - 5 * 60) * 1000 return True, None except Exception as e: raise ApiCallError(format(repr(e)))
def cidr_iprange(ipaddr, cidrmask): """ Creates a generator that iterated through all of the IP addresses in a range given in CIDR notation """ # Get all the binary one's mask = (long(2)**long(32 - long(cidrmask))) - 1 b = ipaddr_to_binary(ipaddr) e = ipaddr_to_binary(ipaddr) b = long(b & ~mask) e = long(e | mask) while (b <= e): yield binary_to_ipaddr(b) b = b + 1
def addOperators(nums, targets, diff, curNum, out, rest): if len(nums) == 0 and curNum == targets: rest.append(out) return for i in range(1, len(nums) + 1): cur = nums[:i] if len(cur) > 1 and cur[0] == '0': return nxt = nums[i:] if len(out) > 0: addOperators(nxt, targets, long(cur), curNum + long(cur), out + '+' + cur, rest) addOperators(nxt, targets, -long(cur), curNum - long(cur), out + '-' + cur, rest) addOperators(nxt, targets, diff * long(cur), (curNum - diff) + diff * long(cur), out + '*' + cur, rest) else: addOperators(nxt, targets, long(cur), long(cur), cur, rest)
def __init__(self): self.retry_time_from_config = long( Config().get_general_value("WaitTime")) self.timeout_from_config = long(Config().get_general_value("Timeout"))
def epochtodate(epoch) -> str: return datetime.fromtimestamp( long(epoch)).strftime('%a (%d/%m) at %I:%M %p')
#Long.parseUnsignedLong("8") from types import * from numpy.core import long s = long("16676350960586457059") print(s)
import threading from numpy.core import long from pip._vendor.distlib.compat import raw_input class Number(threading.Thread): def __init__(self, num): threading.Thread.__init__(self) self.num = num def run(self): if self.num % 2 == 0: print("%d is even number\n" % self.num) else: print("%d is odd number\n" % self.num) threads = [] while True: input = long(raw_input("Number(0 to exit): ")) if (input == 0): break thread = Number(input) threads.append(thread) thread.start() for thr in threads: thr.join()
from math import * from numpy.core import long def isPrime(n, i): #print("n = ",n," i = ", i) if i == 1: return True else: if n % i == 0: return False else: isPrime(n, i - 1) test = int(input()) for test in range(test): num = long(input()) if num == 2: print("Prime") continue else: prime = bool(isPrime(num, int(sqrt(num) + 1))) print("Prime = ", prime) print("Prime") if prime == True else print("Not Prime")
def _is_token_expired(self): """is access token expired""" if self.access_token is None: """ need refresh token """ return True return long(round(time.time() * 1000)) >= self.token_expired_time
import subprocess import netifaces from functools import reduce from numpy.core import long ip2int = lambda ip: reduce(lambda a, b: long(a) * 256 + long(b), ip.split('.')) int2ip = lambda num: '.'.join( [str((num >> 8 * i) % 256) for i in [3, 2, 1, 0]]) # print(netifaces.interfaces()) addrs = netifaces.ifaddresses('wlp2s0') ip = addrs[netifaces.AF_INET][0]['addr'] mask = addrs[netifaces.AF_INET][0]["netmask"] def available(ip): ret = subprocess.Popen(['fping', '-a', '-c', '1', ip], stderr=subprocess.PIPE) ret.wait() if ret.returncode == 0: return True return False mask_int = ip2int(mask) ip_int = ip2int(ip) zeroslots = mask_int ^ 0b11111111111111111111111111111111 startIP_int = ip_int & mask_int startIP = int2ip(startIP_int) endIP_int = startIP_int ^ zeroslots endIP = int2ip(endIP_int)