Skip to content

Instantly share code, notes, and snippets.

View clemensg's full-sized avatar

Clemens Gruber clemensg

View GitHub Profile
@endafarrell
endafarrell / icu.py
Created June 7, 2020 18:12
Fix for pyicu's `AttributeError: 'module' object has no attribute 'Locale'`: overwrite the contents of `/usr/local/lib/python2.7/dist-packages/parsedatetime//pdt_locales/icu.py` with this
# -*- encoding: utf-8 -*-
"""
pdt_locales
All of the included locale classes shipped with pdt.
"""
import datetime
try:
# speed up pluck
class ActiveRecord::Relation
class RailsDateTimeDecoder < PG::SimpleDecoder
def decode(string, tuple=nil, field=nil)
if Rails.version >= "4.2.0"
@caster ||= ActiveRecord::Type::DateTime.new
@caster.type_cast_from_database(string)
else
@jorgenpt
jorgenpt / SaneMinMaxMacros.h
Last active September 1, 2023 09:04
An attempt at some saner min-max-clamp macros for C and Objective-C. Require a modern compiler (C11) with support for statement expressions (Gnu11).
#pragma once
#define _CheckTypes(a,b) _Static_assert(_Generic(a, typeof (b):1, default: 0), "Mismatched types")
#define Min(a,b) \
({ \
const typeof (a) _a = (a); \
const typeof (b) _b = (b); \
_CheckTypes(_a,_b); \
(_a < _b ? _a : _b); \
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@purcell
purcell / application_helper.rb
Created September 9, 2011 09:23
Make will_paginate generate HTML that bootstrap.less will render nicely
# Based on https://gist.github.com/1182136
class BootstrapLinkRenderer < ::WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag :div, tag(:ul, html), container_attributes
end
def page_number(page)
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)