Categories
Uncategorized

Simple File Lists – python

How to make quick directory lists in python. All of these will use listdir in the os module. so we need to import it first Now we want to list all the files in a directory called my_folder. But the trick is that we only want the text files. Another thing we can do is […]

Categories
Uncategorized

Using Regex in MySQL

Very simple really That’s it.

Categories
Uncategorized

MySQL Node Matrix – Python

This will create either a directed or an undirected matrix on a MySQL data base. The edges are written as tuples, like this Where the first item in the tuple is the from node, the second item is the to node, and the third item is the weight of the edge. Here is the code […]

Categories
Uncategorized

Using regex search and grouping – Python

For some silly reason we have a string with the following information We can use the regular expressions module to find and group the relevant information…just like this. That should output The regex broken down This gives us the name This gives us the telephone number Finally, this will give us the id

Categories
Uncategorized

Formatting Integers – Python

We have a range from 1 to 100 and we want to format the integers so that they look nice. Something like this so first we create the range which should result in something like this The actual formatting code is quite simple, this But to apply it to a list, we can do this […]

Categories
Uncategorized

Adding new entries to database – Python & MySQL

Checking to see if an entry exists in the database, if not, then add it Currently, in the database we only have two names, ‘Shaniqua’ and ‘Jose’ But the new list of names contains a new person ‘Latifah’. Here is how the db can be updated

Categories
Uncategorized

Selecting and Entering Values – MYSQL

This is how to enter a specific value in a column depending on the value of another column. So we have a table called ‘t_main’ in a database called ‘db_sample’, and it looks something like this. Name Stat1 Status Module 1 23 Module 2 50 Module 3 31 And we want to see if we […]

Categories
Uncategorized

Scraping HTML Generated by JavaScript – Python

Say we want to get some data from stats.cyanogenmod.com. If we were to do a simple wget or curl on the above url, all we would get would be something like this. and within the HTML we can see the following lines this is the bit that generates the actual data we want to download. […]

Categories
Uncategorized

Robots Now Taking Your Orders – Python

There was a post on r/technology about robots potentially taking over from humans if the minimum wage rises. After someone made a comment about robots not being able to spit in your food, u/angryPenguinator replied with a script written in BASIC that describes a robot putting crap on your burger. Now I will try it […]

Categories
Uncategorized

Synchronising two folders – Python

It’s friday…more code for sh*ts and giggles. Limitations and that…. This is a very simple and basic script that will synchronise two directories. It works as long as the files have the same name. It works by measuring the time the files were changed and replacing the older one with the newest one. Again…it will […]