Skip to content

Instantly share code, notes, and snippets.

# Write Python 3 code in this online editor and run it.
class SomeAbstraction:
pass # lots of stuff - but missing something
class Mixin1:
def something(self):
pass # one implementation
def show(self):
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
class Duck(object):
# Class attributes definition
def __init__(self):
# Instance attributes definition
self.fly_behavior = None
pass # lots of stuff - but missing something
@omarjcero
omarjcero / tcp_string_sender.py
Created July 29, 2021 15:30
Simple script to convert a numeric comma separated string into an ascii string, and send it to a TCP port
import socket
import sys
def prepare_data_to_send(str_comma_separated):
data = ''.join([chr(int(i)) for i in str_comma_separated.split(',')])
return data
try:
@omarjcero
omarjcero / get_class_name.php
Created August 2, 2021 22:08
PHP snippet to find class path
<?
class Foo {}
$reflector = new \ReflectionClass('Foo');
echo $reflector->getFileName();
?>
@omarjcero
omarjcero / find.sh
Created August 3, 2021 15:14
Linux command I use to find what file contains a key word
grep -E "some_key_word" --include=*.py -rnwi '/srv/code/' -l
@omarjcero
omarjcero / mysql_class.py
Created August 3, 2021 19:39
MySQL simple class to handle queries in python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymysql
class ConexionMySQL:
def __init__(self, host, user, pwd, dbname):
a = [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
print(a[1:]) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
print(a[-1]) # [13]
print(a[-4:]) # [10, 11, 12, 13]
print(a[1:-4]) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(a[1:10]) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
@omarjcero
omarjcero / query_rows_2_dict.py
Created October 28, 2021 17:40
Get a dictionary from query in python
cursor = connection.cursor()
cursor.execute(sql)
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
print(results)
@omarjcero
omarjcero / port.sh
Created November 26, 2021 15:01
Linux command to find what running PID is using an specific port
$ netstat -nlp | grep :12159
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 9 0 0.0.0.0:12159 0.0.0.0:* LISTEN 73809/python
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 40 columns, instead of 14. in line 7.
FileName,Date,SegFile,b,e,LBE,LB,AC,FM,UC,ASTV,MSTV,ALTV,MLTV,DL,DS,DP,DR,Width,Min,Max,Nmax,Nzeros,Mode,Mean,Median,Variance,Tendency,A,B,C,D,E,AD,DE,LD,FS,SUSP,CLASS,NSP
Variab10.txt,12/1/1996,CTG0001.txt,240,357,120,120,0,0,0,73,0.5,43,2.4,0,0,0,0,64,62,126,2,0,120,137,121,73,1,0,0,0,0,0,0,0,0,1,0,9,2
Fmcs_1.txt,5/3/1996,CTG0002.txt,5,632,132,132,4,0,4,17,2.1,0,10.4,2,0,0,0,130,68,198,6,1,141,136,140,12,0,0,0,0,0,0,1,0,0,0,0,6,1
Fmcs_1.txt,5/3/1996,CTG0003.txt,177,779,133,133,2,0,5,16,2.1,0,13.4,2,0,0,0,130,68,198,5,1,141,135,138,13,0,0,0,0,0,0,1,0,0,0,0,6,1
Fmcs_1.txt,5/3/1996,CTG0004.txt,411,1192,134,134,2,0,6,16,2.4,0,23,2,0,0,0,117,53,170,11,0,137,134,137,13,1,0,0,0,0,0,1,0,0,0,0,6,1
Fmcs_1.txt,5/3/1996,CTG0005.txt,533,1147,132,132,4,0,5,16,2.4,0,19.9,0,0,0,0,117,53,170,9,0,137,136,138,11,1,0,1,0,0,0,0,0,0,0,0,2,1
Fmcs_2.txt,5/3/1996,CTG0006.txt,0,953,134,134,1,0,10,26,5.9,0,0,9,0,2,0,150,50,200,5,3,76,107,107,170,0,0,0,0,0,0,0,0,1,0,0,8,3
Fmcs_2.txt,5/3/1996,CTG0007.txt,240,953,134,134,1,0,9,29,6.3,0,