Category: programming
-
Python – Send Email via Google GMail and Python Script
import smtplib from email.mime.text import MIMEText as text def test_sendmail(): to_address ='”PersonA”<a.b@gmail.com>’ body = “This is the email body!” subject=”Hello World” sendmail(to_address, subject, body) def sendmail(to_address, subject, body): from_address='”This Is Me”<a.b@gmail.com>’ smtp_server = ‘smtp.gmail.com’ smtp_port= 587 smtp_user=”a.b@gmail.com” smtp_password=”abcdefgh” #———compose——- msg = text(body) msg[‘Subject’] = subject msg[‘From’] = from_address msg[‘To’] = to_address #———send——- server = smtplib.SMTP(smtp_server,…
-
JQuery – Alternatives and Drop-In Replacement of jQuery JavaScript Library
The following small javascript libraries can be used instead of and as drop-in replacements of jQuery. My favorites (based on size and/or functionality) [github file = “/sudar/MissileLauncher/blob/master/MissileLauncher.cpp”] 1. ki.js: https://github.com/dciccale/ki.js 2. minifiedjs: http://minifiedjs.com/ 3. psQuery: https://github.com/pseudosavant/psQuery 4. Zepto.js: Zepto.js 5. riloadr: riloadr References 1. http://microjs.com/
-
Lean Virtual Servers in Germany 2015
The following companies offer virtual servers on transparent, lean and competitive prices. Additionally all their offers are easily cancellable monthly via online interface 🙂 contabo.de, 7,99 EUR, 2Core, 6GB, 500GB HDD, https://contabo.de/?show=konfigurator&vserver_id=130 netcup.de, 7,99 EUR, 2Core, 6GB, 120GB HDD, https://www.netcup.de/bestellen/produkt.php?produkt=1001 noez.de: 6,50 EUR, 4Core, 2GB, 250GB HDD, https://noez.de/vserver/medium/ x4-tec.com: 6,40 EUR, 3Core, 2GB, 100GB…
-
Python – String to Number Hash
def string2numeric_hash(text): import hashlib return int(hashlib.md5(text).hexdigest()[:8], 16) # test >>print string2numeric_hash(‘this is a nice string’) 1962341389 References 1. http://stackoverflow.com/questions/2511058/persistent-hashing-of-strings-in-python
-
Requests per Second from Logfiles – Nginx, Apache
Requests per Second from Logfiles – Nginx, Apache http://stackoverflow.com/questions/4051555/how-do-i-get-the-number-of-requests-per-second-from-apache-log-between-2-dates-t while true; do tail -n0 -f /var/log/wowza/wowzamediaserver_access.log>/tmp/tmp.log & sleep 2; kill $! ; wc -l /tmp/tmp.log | cut -c-2; done 2>/dev/null As a bash function/alias rqs /var/log/access.log function requests_per_second(log_filepath){ # http://stackoverflow.com/questions/4051555/how-do-i-get-the-number-of-requests-per-second-from-apache-log-between-2-dates-t while true; do tail -n0 -f “${log_filepath}” > /tmp/tmp.log & sleep 2; kill $!; wc…
-
Python – Headless Selenium Performance Tests with Google Chrome, Browsermob-Proxy and Xvfb
# -*- coding: utf-8 -*- “”” # Install xvfb sudo apt-get install -y xvfb # create build directory mkdir -p ~/build/selenium cd ~/build/selenium # Install API for browsermob-proxy and selenium sudo pip install selenium browsermob-proxy –upgrade # download browsermob proxy wget https://github.com/downloads/webmetrics/browsermob-proxy/browsermob-proxy-2.0-beta-6-bin.zip unzip browsermob-proxy-2.0-beta-6-bin.zip # copy browsermob-proxy to /var/lib sudo cp -r browsermob-proxy /var/lib/ sudo…
-
SED – Custom Separators – Dealing with Filepaths
a@t400:~$ echo “hello”| sed -e ‘s/e/ö/g’ höllo a@t400:~$ echo “hello”| sed -e ‘s#e#ö#g’ höllo a@t400:~$ echo “hello”| sed -e ‘s^e^ö^g’ höllo References http://backreference.org/2010/02/20/using-different-delimiters-in-sed/
-
Python – Using the Bing Search API
Introduction Bing is a great search engine with very generous API volumes for developers. Currently 5.000 queries per month can be called for free. Compare with Google: 100 per day * 30 = 3.000 per month. There a couple of Python libraries which used to work with Bing API. I tried pybing but the the…
-
Python – Spynner – Test Scripts
Spynner is a stateful programmatic web browser module for Python based on PyQT and WebKit. How to install Spynner – easy 🙂 > cat spynner-test.py # -*- coding: utf-8 -*- import spynner import pyquery import os os.environ[‘DISPLAY’] = ‘:0.0’ def main(): browse_via_jquery() browse_using_xpath() browse_via_webkit() download_image() def browse_via_jquery(): browser = spynner.Browser(debug_level=spynner.DEBUG) browser.create_webview() browser.show() #browser.hide() browser.load(“http://www.wordreference.com”) browser.load_jquery(True)…
-
Unix – Rename Files recursively using a for-loop and find command
find . -name “*.flv.mp4” | while read file; do echo “$file”; mv “$file” “${file%.flv.mp4}.mp4” #mv “$file” “$(expr “$file” : ‘\(.*\)\.flv.mp4’).mp4″ done; Notes: rename rename does not work: “$rename .html .txt *.html” results in… syntax error at (eval 1) line 1, near “.” basename basename does not work – only renames the filename and strip path!…