Skip to content

Instantly share code, notes, and snippets.

View jordillonch's full-sized avatar

Jordi Llonch jordillonch

  • Barcelona
View GitHub Profile
DELIMITER |
CREATE FUNCTION UuidFromBin(b BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(b);
RETURN LCASE(CONCAT_WS('-',SUBSTR(hex,1, 8), SUBSTR(hex, 9,4), SUBSTR(hex, 13,4), SUBSTR(hex, 17,4), SUBSTR(hex, 21, 12)));
END
|
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
@jordillonch
jordillonch / Ranking.sql
Created June 3, 2014 16:20
MySQL rankings
SET @rank := 1;
SET @curr := null;
SELECT
@prev := @curr,
@curr := group_field,
@rank := IF(@prev = @curr, @rank+1, 1) AS rank,
id
FROM table_name
order by group_field;
@jordillonch
jordillonch / CollectionProcessor.php
Created June 2, 2014 15:00
Iterator implementation
final class CollectionProcessor implements Iterator
{
private $position = 0;
/** @var ProcessorInterface[] */
private $collection = [];
public function __construct()
{
$this->position = 0;
}

Keybase proof

I hereby claim:

  • I am jordillonch on github.
  • I am jordillonch (https://keybase.io/jordillonch) on keybase.
  • I have a public key whose fingerprint is 3540 1047 D9F2 BBF2 C945 E366 147D FDD2 2B27 A6B6

To claim this, I am signing this object:

@jordillonch
jordillonch / async_fetcher.php
Created March 29, 2014 22:42
HHVM async example using curl_multi_exec
<?hh
// Based on https://gist.github.com/chregu/9740519
class Fetcher {
// async function: http://docs.hhvm.com/manual/en/hack.async.php
// return type annotation: http://docs.hhvm.com/manual/en/hack.annotations.introexample.php
// generics: http://docs.hhvm.com/manual/en/hack.generics.php
public async function fetch(string $url) : Awaitable<array>
{
@jordillonch
jordillonch / blocks_insert.php
Created March 2, 2014 08:43
insert into table from select slitting data in blocks
<?php
$mysqli = new mysqli("localhost", "root", "", "test");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$tableTo = 'table_from';
@jordillonch
jordillonch / transpose_columns_to_rows.sql
Created January 22, 2014 12:05
Transpose columns to rows in MySQL
SET SESSION group_concat_max_len = 100000;
SET @sql = NULL;
SELECT
GROUP_CONCAT(
CONCAT(
'select fecha, ''',
c.column_name,
''' as c, ',
c.column_name,
@jordillonch
jordillonch / Open new Safari window
Created January 19, 2014 22:49
Open new Safari window
tell application "Safari"
make new document with properties {URL:""}
end tell
@jordillonch
jordillonch / Open new iTerm2 window
Created January 19, 2014 22:49
Open new iTerm2 window
tell application "iTerm 2"
tell (make new terminal)
launch session "Default"
end tell
activate
end tell