Skip to content

Instantly share code, notes, and snippets.

@georgepsarakis
georgepsarakis / python-mr.py
Last active October 21, 2019 16:57
Python MapReduce (itertools, multiprocessing)
#!/usr/bin/env python
import os
import itertools
import multiprocessing as mp
from math import ceil
from types import GeneratorType as generator
from functools import partial
from time import time
@georgepsarakis
georgepsarakis / templater.php
Last active December 28, 2015 11:59
PHP Templating
<?php
class T {
protected $Context = array();
protected $Compiled = NULL;
public $Regex_Variable = '~\{\{\s+[a-z_0-9\|:\.]+\s+\}\}~imsu';
public $Separator_Filter = '|';
public $Separator_Directive = ':';
protected $HTML_Encoder = NULL;
protected $HTML_ENCODE = TRUE;
protected $VALUE_CACHE = array();
@georgepsarakis
georgepsarakis / lighter.js
Last active December 25, 2015 20:39
Extra-Lightweight HTML/Markdown Editor (jQuery Plugin)
/*
<div id="editor"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
.clearfix:after {
clear: both;
}
.clearfix:before, .clearfix:after {
content: " ";
display: table;
@konklone
konklone / ssl.rules
Last active August 8, 2023 08:39
nginx TLS / SSL configuration options for konklone.com
# Basically the nginx configuration I use at konklone.com.
# I check it using https://www.ssllabs.com/ssltest/analyze.html?d=konklone.com
#
# To provide feedback, please tweet at @konklone or email eric@konklone.com.
# Comments on gists don't notify the author.
#
# Thanks to WubTheCaptain (https://wubthecaptain.eu) for his help and ciphersuites.
# Thanks to Ilya Grigorik (https://www.igvita.com) for constant inspiration.
server {
@mblondel
mblondel / kernel_kmeans.py
Last active January 4, 2024 11:45
Kernel K-means.
"""Kernel K-means"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.utils import check_random_state
@jasonrudolph
jasonrudolph / 00-about-search-api-examples.md
Last active January 31, 2024 09:22
5 entertaining things you can find with the GitHub Search API
@algal
algal / nginx-cors.conf
Created April 29, 2013 10:52
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@duncansmart
duncansmart / progressive-ace.htm
Created March 28, 2013 23:29
Integrating ACE Editor in a progressive way
<textarea name="my-xml-editor" data-editor="xml" rows="15"></textarea>
...
<textarea name="my-markdown-editor" data-editor="markdown" rows="15"></textarea>
...
<script src="//d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js"></script>
<script>
// Hook up ACE editor to all textareas with data-editor attribute
$(function () {
@georgepsarakis
georgepsarakis / split.sql
Created March 3, 2013 21:02
Split (explode) function for MySQL. Simple version requires 3 arguments, S (the delimited string), DELIM (delimiter) and S_INDEX the index of the instance of substring between delimiters. The LTSPLIT, RTSPLIT & TSPLIT wrappers perform trimming on the returned substring, on leading, trailing & both characters respectively.
DROP FUNCTION IF EXISTS SPLIT;
DROP FUNCTION IF EXISTS _SPLIT;
DROP FUNCTION IF EXISTS RTSPLIT;
DROP FUNCTION IF EXISTS LTSPLIT;
DELIMITER //
-- Simple Split (no trim)
CREATE FUNCTION SPLIT(S CHAR(255), DELIM VARCHAR(30), S_INDEX TINYINT UNSIGNED) RETURNS VARCHAR(255)
BEGIN
RETURN _SPLIT(S, DELIM, S_INDEX, '', 0);
@drewkerrigan
drewkerrigan / gist:4218222
Created December 5, 2012 18:31
php multi-get mapred
require("riak-php-client/riak.php");
$client = new RiakClient('127.0.0.1', 8098);
$mr = new RiakMapReduce($client);
$keys = array("TFrWAVz8RRVEEqCH3nS27O4InLB","FEwZgNI4VTJSIZxSas0QpOCCXjn","EkSkmblyIAT5VL7xYpScP2GP71G");
foreach ($keys as $key) {
$mr->add("local_ns~users", $key);
}
$mr->map("Riak.mapValues");