Skip to content

Instantly share code, notes, and snippets.

tell application "Todoist"
activate
tell application "System Events" to keystroke "q"
delay 0.2
tell application "System Events" to keystroke "test task from AppleScript"
delay 0.2
tell application "System Events" to key code 76 -- press enter
end tell
@hakanserce
hakanserce / RubyImapExample.rb
Created May 13, 2019 21:57
Example ruby Imap library usage. Also demonstrates using keychain in MacOS to get password
require 'net/imap'
def get_exchange_password()
pass = %x(/usr/bin/security find-generic-password -w -s Exchange ~/Library/Keychains/login.keychain)
return pass.strip
end
imap = Net::IMAP.new("<IMAP SERVER>", <PORT>, true)
imap.login(<USERNAME>, get_exchange_password)
@hakanserce
hakanserce / OutlookUriHandler.scpt
Created January 20, 2019 08:28
Custom protocol handler for outlook urls...
on open location this_URL
set the messageId to text 11 thru -1 of this_URL
tell application "Microsoft Outlook"
activate
open message id messageId
end tell
end open location
@hakanserce
hakanserce / macos_script_outlook_copy_selected_message_id.scpt
Last active February 24, 2020 09:16
MacOS Apple Script/Javascript Experiment with Creating Links to Outlook Messages. Use MacOS ScriptEditor.app to play with the following.
function getCurrentApp() {
app = Application.currentApplication();
app.includeStandardAdditions = true;
return app;
}
function copyToClipboard(text) {
getCurrentApp().setTheClipboardTo(text)
}
@hakanserce
hakanserce / FractalTree.java
Created June 3, 2017 11:29
A quick and dirty fractal based tree visualization in Java Swing...
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.BasicStroke;
import java.awt.Color;
class TreePanel extends JPanel {
private float innerAngle;
@hakanserce
hakanserce / numpy_polynomial_features.py
Created May 26, 2017 15:25
Calculates polynomial features of a matrix for each row up to an order (can be used with regression, for instance)
# Calculate polynomial features
# Adapted from https://stackoverflow.com/questions/11723779/2d-numpy-power-for-polynomial-expansion
def polynomial_features(x, order):
x = np.asarray(x).T[np.newaxis]
n = x.shape[1]
power_matrix = np.tile(np.arange(order + 1), (n, 1)).T[..., np.newaxis]
X = np.power(x, power_matrix)
I = np.indices((order + 1, ) * n).reshape((n, (order + 1) ** n)).T
# @hakanserce - my changes start
@hakanserce
hakanserce / HyperParameterOptimization.py
Created May 12, 2017 17:04
Using KFold cross correlation for hyper-parameter optimization...
# This gist uses RBF Kernel based Ridge Regression: https://gist.github.com/hakanserce/fdd571132ef44a6a8f7ddd2eb41aba84
kf = KFold(y_train.size, n_folds=5)
X_all = np.hstack((X_train, X_test))
y_all = np.hstack((y_train, y_test))
def get_cross_validated_mses(rbf_lambda, d2):
for train, test in kf:
@hakanserce
hakanserce / BasisFunctionRidgeRegression.py
Last active May 12, 2017 16:57
A Ridge Regression implementation attempt in python which allows using arbitrary basis function... Includes RBF as well.
import matplotlib.pyplot as plt
import numpy as np
# A Ridge Regression implementation which allows using arbitrary basis functions.
class BasisFunctionRidgeRegression(object):
def __init__(self, basis_transform, d2):
self.theta = None
self.basis_transform = basis_transform
@hakanserce
hakanserce / Elasticsearch17UpsertScripting.md
Created December 7, 2016 08:48
ow Elasticsearch handles upsert scripts (v 1.7)

#How Elasticsearch handles upsert scripts (v 1.7)

Copied code over from https://github.com/elastic/elasticsearch/blob/1.7/src/main/java/org/elasticsearch/action/update/UpdateHelper.java for reference...

public Result prepare(UpdateRequest request, IndexShard indexShard) {
      long getDateNS = System.nanoTime();
      final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
              new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME},
              true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE, false);
@hakanserce
hakanserce / JsonInitial.g4
Created November 26, 2016 10:36
A Json grammar with ANTLR (string and number definitions does not cover full definitions)
grammar Json;
struct: ('{' '}') | ('{' attribute (',' attribute)* '}');
attribute: STRING ':' value;
value: NUMBER | BOOLEAN | STRING | struct | list;
list: ('[' ']') | ('[' value (',' value)* ']');
NUMBER: ('+'|'-')? ('0'..'9')+ ('.' ('0'..'9')+)?;
BOOLEAN: 'true' | 'false';
STRING: '"' ~('"'|'\\')* '"';