DN42 is a wonderful project that allows you to develop your BGP skills without breaking the product environment, without having to have expensive devices to make a lab to do simulations with GNS3. At the same time, it should not be a purely laboratory environment in which there are no real-world problems. I participate with 1 node in the project for about a year. One of the problems in the project is 1:1 with the real world – when someone announces prefixes that they shouldn't announce. Because I'm lazy and I don't write filters by hand all the time, I solved the problem with an elementary bash script that generates a prefix-list named dn42 and I pour the valid prefixes in it.

#!/bin/bash</pre>
vtysh -c 'conf t' -c "no ip prefix-list dn42"; #drop old prefix list

while read pl
do
vtysh -c 'conf t' -c "$pl"; #insert prefix list row by row
done < <(curl -s https://ca.dn42.us/reg/filter.txt | grep -e ^[0-9] | awk '{ print "ip prefix-list dn42 seq " $1 " " $2 " " $3 " ge " $4 " le " $5}' | sed "s_/\([0-9]\+\) ge \1_/\1_g;s_/\([0-9]\+\) le \1_/\1_g");
vtysh -c 'wr' #write new prefix list

The list of valid prefixes is taken https://ca.dn42.us/reg/filter.txt from where the main pipeline + a few modifications on my part to be able to generate prefix sheets. Commands are executed through vtysh.

My favorite text editor is Geany. It is very minimalist HERE which supports a huge set of languages – shell, php, python, C … etc. It has automatic finishing and at the same time it is very agile. It lacks some other pleasant opportunity, but at the moment it is more than enough for me. I started an online course Python Programming на SoftUni – to refresh my knowledge and upgrade it because I have not adequately monitored what is happening with python 3. The lecturers of the course recommend PyCharm as an IDE for pyton programming, but I do not like it, of course I use Geany for the exercises.

During the lectures I felt painfully 2 lacks

  1. python autocomplete exhales from documentation of functions and methods
  2. no validation for pep8 standard

The good thing is that Geany is flexible enough to configure and can be easily supplemented by missing ones.. Sometimes add python documentation to our IDE:

  • we pull the following script somewhere in our PATH for example / usr / bin and don't forget to make it executable
  • edit the file ~ / .config / geany / filedefs / filetypes.python by adding the following line in the settings section context_action_cmd=pydocw %s. If there is only add the name of the binary from the previous step. We restart Geany if it is released.
  • We already have a context-action that will get you information about the function. I added a shortcut to make it more convenient as I do not understand any functionality. I like this approach a lot because I am very annoyed by the netbeans approach.

So far so good. Then I really want to have validation of the code I write – whether I write it according to generally accepted standards or I write some ugliness. Basically I found it again tutorials how things happen but it's a bit outdated – Geany has everything built into it, you just need to install the pep8 package. In Debian apt-get install pep8 works in the other distros you have to find out for yourself how the magic happens. In the Build menu, the second button (at least for me) is Lint after clicking it you will find how ugly code you have created 😀

Screenshot from 2016-01-11 20-42-21

Here's a general outline of how to make your Geany work better with Python while still being fast without making your CPU want to pull the bullet.

Changing a domain in WordPress is a pain. I've had to do a few lately and things are happening sportily fast 😀 . If I can summarize the steps are 2 – of course without moving the files, настройките ако се сменя изцяло хостинга.

1. Промяна на старото URL със новототука нещата са тривиални. Отваряте си wp-config.php файлът и във него поставяте следните 2 order

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Като замествате http://example.com със вашият нов.

2. So far, the site opens well, the urls work, but the uploaded content as pictures, documents and so on are not visible. Rough intervention is already required here. The old urls must be replaced with the new ones in the database. This was a terribly unpleasant process, especially for novice users, which do not handle SQL syntax well, but there is already a pretty nice script searchreplacedb2, who does everything unpleasant for you. Its use is trivial – you upload it to the main directory where your wordpress page is located and open it through your browser. След това следвате стъпките като първо ще ви пита за потребителско име и парола който е взел от вашия wp-config.php и след това ще ви пита за новото и старото url. After the last step you will have to wait for me it took an average of 40 seconds -50 seconds.

This is basically nothing difficult or super complicated.

A shell script wants your job

Today while I was working I saw that one of the machines was lying very badly. I go into it watching a cron bump into a hell of a lot of zombie processes (roughly around 50-60). There was no way I could kill them all with killall so I had to make a little more competent solution to the problem – to draw an elementary bash a script to find and kill processes. 50-PIDs are not easy to write by hand :D. I scratched the script for a minute and it is very simple, but it still deserves attention 🙂

At its base is the conveyor

ps ax | grep -v grep | grep process_name | awk '{print $1}')

Here we get a sheet with all the PIDs of the process that we have to kill by excluding grep from this list. Now that we have the list, things become easy, everything turns into one for. Here is the end result

#!/bin/bash

PR=$(ps ax | grep -v grep | grep process_name | awk '{print $1}')

for PID in $PR
do
echo "$PID will be killed"
kill -9 $PID
done

Can be “tuning” as the name is taken as an argument after the name of the script and thus is called as executable binary. However, it is not a very good practice to have such frequent cases 😀 But it never prevents us from being protected from any

Enhanced by Zemanta

Image representing MySQL as depicted in CrunchBase

Some time ago I wrote about MySQL Full Text Search 🙂 Today I had a very interesting experience with one request. In general, the query looks for results that are missing from another table. One basic Select and one sub select in the WHERE part of the query. In general, the skeleton is

SELECT DISTINCT (
`field`
)
FROM `table1`
WHERE `someID` =44
AND `firsTextField` NOT
IN (

SELECT DISTINCT (
`secondTextField`
)
FROM `table2`
WHERE `otherID` =44
)

Basically a simple query. I wrote it for 30 sec I run it and the machine loops. After a long and patient wait on my part or more precisely ~ 43 sec . I spat out the result lol . Pffff madhouse. I enter the machine watching the CPU is normally loaded almost in idle condition. Shock and horror. I run the query again the same result. Fuck WTF. I run explain the query and everything shines – the second field secondTextField is only full text search without index, and there the plate is modest of about 35k lines. Who to read – full text search is not an index. The problem is quickly clear one

ALTER TABLE `links` ADD INDEX ( `linkUrlID` ) 

And things fell into place Query took 0.0005 sec 😀

Be careful how you put your indexes, the speed of the query depends on them marginally.

p.s In general, I am to blame for the above situation not only because it lacks an index but because it does not use the full text search method 😀

Enhanced by Zemanta