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 / convert-geojson-to-wkt.py
Created May 12, 2014 22:13
Convert GeoJSON to/from WKT in Python. #python #geojson #geometry
import json
import geojson
from shapely.geometry import shape
o = {
"coordinates": [[[23.314208, 37.768469], [24.039306, 37.768469], [24.039306, 38.214372], [23.314208, 38.214372], [23.314208, 37.768469]]],
"type": "Polygon"
}
s = json.dumps(o)
@drmalex07
drmalex07 / test-datetime-json-dumps.py
Created May 15, 2014 12:57
Create JSON dumps aware of datetime.datetime objects, in Python. #json #python #dumps #datetime
import json
import datetime
'''Create an encoder subclassing JSON.encoder.
Make this encoder aware of our classes (e.g. datetime.datetime objects)
'''
class Encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
@drmalex07
drmalex07 / load-pylons-wsgi.py
Created June 16, 2014 07:35
Load a Pylons-based WSGI application inside its environment. #python #paster #pylons #wsgi
import logging, logging.config
import os
here = os.path.dirname(os.path.realpath(__file__))
ini_file = os.path.join(here, 'development.ini')
# Activate enviroment
activate_this = os.path.realpath(os.path.join(here, '../..', 'bin/activate_this.py'))
execfile(activate_this, dict(__file__=activate_this))
@drmalex07
drmalex07 / TestSkipValidation.java
Last active November 2, 2023 17:10
Create a new Java keystore. Add your trusted certificates. #java #jks #certificate #ssl #keystore
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
@drmalex07
drmalex07 / class-decorator-example.py
Created June 24, 2014 07:21
Create a class decorator in Python. #python #decorator #class-decorator
import logging
pairs = []
def baz_decorator(target_cls):
def decorate(cls):
logging.info('Decorating class %s with target %s' %(cls, target_cls))
pairs.append((cls, target_cls))
return cls
return decorate
@drmalex07
drmalex07 / configure-sendmail-as-relay.md
Last active May 15, 2026 18:24
Configure sendmail as an SMTP smart host (relay). #smtp #sendmail #relay #mail

Note: Prefer Exim4 over Sendmail

Configure sendmail

Append the following directives into /etc/mail/sendmail.mc. These lines should come before mailer definitions.

define(`SMART_HOST',`mail.example.com')
define(`RELAY_MAILER_ARGS', `TCP $h 587')
@drmalex07
drmalex07 / getopt-example.sh
Last active May 3, 2025 11:08
A small example on Bash getopts. #bash #getopt #getopts
#!/bin/bash
#
# Example using getopt (vs builtin getopts) that can also handle long options.
# Another clean example can be found at:
# http://www.bahmanm.com/blogs/command-line-options-how-to-parse-in-bash-using-getopt
#
aflag=n
bflag=n
@drmalex07
drmalex07 / format-example.py
Created September 18, 2014 17:59
An example of using __format__ magic method in Python. #python #format
class Foo(object):
def __init__(self, x):
self._x = x
def __format__(self, format_spec):
return '<Foo x={0}>'.format(self._x)
foo = Foo(12)
@drmalex07
drmalex07 / memoize-example.py
Created September 23, 2014 17:02
An example memoize decorator for Python. #python #memoize #decorator
_cache = dict()
def memoize(fn):
print 'Creating wrapper for %r ...' %(fn)
cached_results = _cache[fn] = dict()
def wrap(*args):
cid = args
if cid in cached_results:
res = cached_results[cid]
else:
@drmalex07
drmalex07 / oop-super-example-1.py
Last active August 29, 2015 14:06
An example on Python's super() function. #python #oop #python-super #inheritance
# Demonstate super() on a simple-inheritance scenario
class A(object):
def __init__(self, x):
self.x = x
def foo(self, y):
print 'A.foo(%r) on instance %r' %(y, self)