Labels

Android (1) Apache (1) bash (2) boost (2) C (37) C++ (5) cheatsheet (2) CLion (6) css (3) Debian (34) DL (17) dns (1) Docker (3) Dreamweaver (2) Eclipse (3) fail2ban (5) git (6) GitHub (5) Hacking (4) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (33) javascript (3) Linux (182) Mac (21) Machine Learning (1) mySQL (53) Netbeans (6) Networking (1) Nexus (1) OpenVMS (6) Oracle (4) Pandas (3) php (17) Postgresql (8) Python (9) raid (1) RedHat (15) Samba (2) Slackware (52) SQL (14) ssh (1) svn (1) tar (1) ThinkPad (1) Virtualbox (4) Visual Basic (2) Visual Studio (1) Windows (7) wire (1)
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, 16 May 2020

PHP variables and scope

In php variables have scope (don't all languages)...

A variable declared outside of a function will not be available inside of a function, unless be declare it inside the function with the global command.

Tuesday, 11 February 2020

Printing via UDP in Python

TO BE TESTED

import socket
import system
udpSocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
message ="SEND THIS TO ZEBRA"
ip='192.168.0.100'
port=20000
udpSocket.sendto(message,(ip,port))
 
 
 
Socket clientSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
clientSocket.NoDelay = true;

IPAddress ip = IPAddress.Parse("192.168.192.6");
IPEndPoint ipep = new IPEndPoint(ip, 9100);
clientSocket.Connect(ipep);

byte[] fileBytes = File.ReadAllBytes("test.txt");

clientSocket.Send(fileBytes);
clientSocket.Close(); 

Saturday, 18 January 2020

local http servers

The following starts a basic http server locally in the current directory;

python 2.x

python -m SimpleHTTPServer 8080

python 3.x (untested)

python -m http.server 8080

https://gist.github.com/willurd/5720255

Wednesday, 13 November 2019

Python reading file error - 'utf-8' codec can't decode byte


 
When reading in a file and getting errors such as example:
'utf-8' codec can't decode byte 0xa3 in position 2897: invalid start byte 
 
Add errors='ignore' as per the following example: 
 with open(fname,"r", errors='ignore') as fo:
 
 

Wednesday, 7 August 2019

Configure apache to run python scripts

Edit httpd.conf file to include the following;

Uncomment LoadModule
<IfModule !mpm_prefork_module>
        LoadModule cgid_module lib64/httpd/modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
        LoadModule cgi_module lib64/httpd/modules/mod_cgi.so
</IfModule>

Add ExecCGI
    Options Indexes FollowSymLinks ExecCGI

Add .py
    AddHandler cgi-script .cgi .py

Friday, 9 March 2018

GitHub - Pushing to remote is rejected as a result of email address being exposed

Problem with PyCharm & Clion and gitHub on Mac specifically…

Also found on Debian, probably affects all applications pushing to GitHub


Pushing to remote is rejected as a result of email address being exposed.

Check;

git config --global user.email

If this shows email address, change is as per below;

git config --global user.email “plisken1@users.noreply.github.com”

Friday, 6 October 2017

Python misc

def myFunction(prices, credit):
    for a in range(len(prices)):
        for b in range(a+1,(len(prices))):
            if(prices[a]+prices[b]==credit):
                if (prices[a]>prices[b]):
                    myT=[prices[b],prices[a]]
                    return(myT)
                else:
                    myT=(prices[a],prices[b])
                    return(myT)



prices=(10, 6, 3, 4, 5, 6, 7, 8, 9, 10)
credit=16
print(myFunction(prices,credit))