Skip to content

Instantly share code, notes, and snippets.

View alxarch's full-sized avatar

Alexandros Sigalas alxarch

View GitHub Profile
module.exports = loopify = ([condition, sleep]..., action) ->
unless "function" is typeof condition
sleep ?= +condition
condition = -> yes
unless "function" is typeof action
throw new TypeError "Invalid callback"
sleep = +sleep
handle = null
start = -Infinity
@alxarch
alxarch / katexparse.js
Created March 13, 2015 20:04
katex parse text
(function () {
var replacements = {
"α": "\\alpha",
"β": "\\beta",
"γ": "\\gamma",
"δ": "\\delta",
"ε": "\\epsilon",
"ζ": "\\zeta",
"η": "\\eta",
"θ": "\\theta",
@alxarch
alxarch / geeklish.sql
Created October 26, 2014 10:21
Greek to greeklish for MySQL
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `greeklish`(input text charset utf8) RETURNS text CHARSET utf8
BEGIN
DECLARE result text charset utf8 DEFAULT '';
DECLARE len INT(4) DEFAULT 0;
DECLARE pos INT(4) DEFAULT 1;
DECLARE letter VARCHAR(10) charset utf8;
SET input = LOWER(input);
SET len = CHAR_LENGTH(input);
@alxarch
alxarch / url.coffee
Created October 8, 2014 11:02
url filters for angular
urlModule = angularModule "url", ["ngRoute"]
class Url
constructor: (@baseUrl) ->
absoluteUrl: (url) ->
unless url.match /^(\w+:)?\/\//
url = "/#{url}" unless url[0] is '/'
url = "#{@baseUrl}#{url}"
url
@alxarch
alxarch / tex2mathml.js
Created September 25, 2014 11:42
Hack MathJax to use as a TeX to MathML converter.
MathJax.Hub.Register.MessageHook("End PreProcess", function () {
[].slice.apply(document.querySelectorAll("script[type^=math]")).forEach(function (s) {
var mml = MathJax.InputJax.TeX.Parse(s.innerHTML).mml();
var math = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math");
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
// tricks toMathML extension
mml.parent = {};
var mathml = mml.toMathML()
math.innerHTML = mathml
@alxarch
alxarch / .gitignore
Last active August 29, 2015 14:05
PhantomJS scripts to interact with service.eudoxus.gr
node_modules/
@alxarch
alxarch / numerals.xqm
Last active December 22, 2015 12:59
XQuery numerals module
module namespace num = "http://thinking.gr/modules/numerals";
declare variable $num:valid-greek := "^[ρστυφχψωϠϡͲͳ]?[ικλμνξοπϞϟ]?[αβγδεζηθςϜϝ]$";
declare function num:to-greek($i as xs:integer) as xs:string
{
if($i gt 0 and $i lt 1000) then
let $x100 := op:numeric-integer-divide($i, 100)
let $x10 := op:numeric-integer-divide($i mod 100, 10)
let $x1 := $i mod 10
// Improved unset for multiple values.
unset: function(attr, options){
var unset = {}, i, max;
if(typeof attr === 'string'){
return Backbone.Model.prototype.unset.call(this, arguments);
}
if(attr instanceof Array){
for(i = 0, max = attr.length; i < max; i++){
var Events = function(){};
Events.prototype = {
events: {},
on: function(eventName, callback, context){
if(!this.events[eventName]){
this.events[eventName] = [];
}
this.events[eventName].push([callback, context || this]);
},
@alxarch
alxarch / basex-daemon.sh
Created October 22, 2012 22:04
BaseX startup service script for Debian
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: BaseX Server
# Description: Manage BaseX XML Database Server.
### END INIT INFO