Skip to content

Instantly share code, notes, and snippets.

View drmalex07's full-sized avatar

MichailAlexakis drmalex07

  • IMIS "Athena" Research Center
  • Athens, Greece
View GitHub Profile
@drmalex07
drmalex07 / build-deb-package.md
Last active July 21, 2020 15:28
A simple HowTo build a debian source package. #debian

Create a debian package

Prereqs

Install debian maintainer's toolset:

apt-get install devscripts dh-make

Create skeleton directory

@drmalex07
drmalex07 / drupal-xmlrpc-example-1.py
Last active January 1, 2016 15:29
Invoke Drupal XML-RPC call through Python's xmlrpclib. #drupal #xmlrpclib #php
import xmlrpclib
session_info = (None,None)
token = None
class CookieAwareTransport(xmlrpclib.Transport):
''' Enhance xmlrpclib.Transport so that it sends the
appropriate authn/authz headers
'''
def send_content(self, connection, request_body):
@drmalex07
drmalex07 / git-rebase-example.sh
Created March 14, 2014 12:29
Provide a simple workflow for a git rebase scenario. #git #git-rebase #scm
# Create a branch named "feature-a"
git branch feature-a
# Switch to branch "feature-a" updating your working copy
git checkout feature-a
# Work ...
vim hello.py
vim README
@drmalex07
drmalex07 / intl-datetime-example-1.php
Created March 16, 2014 22:34
An example for a localized formatted date in PHP. #php #datetime #i18n
<?php
$expected_duration = new DateInterval("PT03H30M"); /* 03:30:00 or 3h 30min */
$expected_at = new DateTime('now');
$expected_at->add($expected_duration);
$formatter = new IntlDateFormatter('el_GR', IntlDateFormatter::LONG, IntlDateFormatter::SHORT);
print $formatter->format($expected_at);
@drmalex07
drmalex07 / hg-branch-example-hgrc
Created March 18, 2014 14:08
Provide an example workflow with Mercurial branches. #mercurial #hg #scm
#
# Example configuration for .hgrc
#
[extensions]
extdiff=
graphlog=
@drmalex07
drmalex07 / drupal-entityfieldquery-example-1.php
Last active January 6, 2023 17:12
An example of an EntityFieldQuery in drupal 7. #drupal #php #drupal-entities
<pre><?php
////////////////////////////////////////////////////
// See more at https://drupal.org/node/1343708 //
////////////////////////////////////////////////////
//
// Filter entities based on several {entity,property,field}-based criteria
//
@drmalex07
drmalex07 / smtp-mailer.py
Last active November 19, 2019 18:44
A simple SMTP mailer using Python's smtplib. #python #smtp #mail
import smtplib
import logging
from email.mime.text import MIMEText
class Mailer(object):
def __init__(self, host, port, username, password='', verbose=0):
self.smtp = None
self.host = host
self.port = int(port)
self.username = username
@drmalex07
drmalex07 / test-rrd-thrush-1.py
Created March 29, 2014 08:29
An example of interacting with RRD databases through Python's thrush module. #python #rrd #thrush
import thrush
import thrush.rrd
import random
import math
from datetime import datetime, timedelta
now = datetime.now()
step = timedelta(seconds=30)
t0 = now - timedelta(seconds=3600)
@drmalex07
drmalex07 / argparse-example-1.py
Last active May 24, 2021 17:29
A typical example of Python's argparse combined with configparser . #python #argparse #configparser
import os
import logging
import argparse
import ConfigParser as configparser
from paste.deploy.converters import asbool, asint, aslist
#
# Declare expected command-line arguments
#
@drmalex07
drmalex07 / download-file.py
Created April 6, 2014 11:26
A download helper for Python scripts. #python #download
import sys
import os.path
import urllib2
def download_file(url, dest_file):
try:
ifp = urllib2.urlopen(url, data=None)
with open(dest_file, 'wb') as ofp:
n = 0
s = ifp.read()