Skip to content

Instantly share code, notes, and snippets.

View mrts's full-sized avatar

Mart Sõmermaa mrts

  • Tallinn, Estonia (EET, UTC +2 hours)
View GitHub Profile
ack-grep __unicode --ignore-dir=venv -l | xargs sed -i 's/__unicode/__str/g'
@mrts
mrts / merit-api-glbatch-request.js
Last active April 1, 2018 10:40
glbatch request with Merit API in Node.js
// See API spec here:
// https://www.merit.ee/juhend/muud/Merit_Aktiva_API_specification.pdf
var CryptoJS = require('crypto-js');
var request = require('request');
require('request-debug')(request);
var moment = require('moment');
var API_KEY = '...';
var API_ID = '...';
@mrts
mrts / add-on-delete-to-models.sh
Last active December 30, 2017 16:09
Add on_delete=models.CASCADE to Django models automatically (Django 2.0 migration)
find . -name models.py | xargs sed -i 's/\(ForeignKey(\w\+\)/\1, on_delete=models.CASCADE/; s/\(OneToOneField(\w\+\)/\1, on_delete=models.CASCADE/'
@mrts
mrts / python-anywhere-setup.md
Last active December 16, 2019 15:37
PythonAnywhere Django setup
  1. Open Bash console in PythonAnywhere

  2. Make project directory

  3. Setup virtualenv

     virtualenv --python=python3.6 venv
     . venv/bin/activate
    
  4. Install Django

pip install django

@mrts
mrts / send-email-hide-recipients.py
Created May 29, 2017 20:14
Send mail with Django so that recipients don't see other recipients
from django.core.mail import send_mass_mail
subject = 'test subject'
message = 'test message'
from_email = '[email protected]'
recipient_list = ['[email protected]', '[email protected]', '[email protected]']
messages = [(subject, message, from_email, [recipient]) for recipient in recipient_list]
send_mass_mail(messages)
set -e
set -u
CERT_HOSTNAME=www.example.com
# create private CA key
openssl genrsa -out $CERT_HOSTNAME-CA.key 2048
# create private CA certificate
@mrts
mrts / pom.xml
Last active March 11, 2017 19:03
Separate source locations for unit and integration tests in Maven pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
@mrts
mrts / CGIHTTPServer.py.diff
Created February 6, 2017 21:15
Patch to Python's bundled CGIHTTPServer.py (from Python 2.7) to run Perl scripts. Useful for serving e.g. AWStats files. Copy `Python27/lib/CGIHTTPServer.py` out, apply the patch and run with `python CGIHTTPServer.py` in `wwwroot`. Then open http://localhost:8000/cgi-bin/awstats.pl?config=example.com in browser.
--- /c/Python27/lib/CGIHTTPServer.py 2015-11-02 16:20:08.000000000 +0200
+++ CGIHTTPServer.py 2017-02-06 23:05:09.734462300 +0200
@@ -103,6 +103,11 @@
head, tail = os.path.splitext(path)
return tail.lower() in (".py", ".pyw")
+ def is_perl(self, path):
+ """Test whether argument path is a Perl script."""
+ head, tail = os.path.splitext(path)
+ return tail.lower() in (".pl")
package util;
import org.apache.log4j.Logger;
import org.springframework.util.StopWatch;
public class DebugLogStopwatch implements AutoCloseable {
Logger logger;
StopWatch stopwatch;
import hashlib
import subprocess
from M2Crypto import RSA, EVP
MESSAGE='hello'
KEY='key.pem'
PUBKEY='pubkey.pem'
def sign_with_m2_evp():