Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active December 4, 2024 21:28
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'

Introduction

I was recently asked to explain why I felt disappointed by Haskell, as a language. And, well. Crucified for crucified, I might as well criticise Haskell publicly.

First though, I need to make it explicit that I claim no particular skill with the language - I will in fact vehemently (and convincingly!) argue that I'm a terrible Haskell programmer. And what I'm about to explain is not meant as The Truth, but my current understanding, potentially flawed, incomplete, or flat out incorrect. I welcome any attempt at proving me wrong, because when I dislike something that so many clever people worship, it's usually because I missed an important detail.

Another important point is that this is not meant to convey the idea that Haskell is a bad language. I do feel, however, that the vocal, and sometimes aggressive, reverence in which it's held might lead people to have unreasonable expectations. It certainly was my case, and the reason I'm writing this.

Type classes

I love the concept of type class

@Drup
Drup / difflist.ml
Last active June 12, 2023 17:26
Difference lists and Miniformat
type ('ty,'v) t =
| Nil : ('v, 'v) t
| Cons : 'a * ('ty, 'v) t -> ('a -> 'ty, 'v) t
let cons x l = Cons (x,l)
let plus1 l = Cons ((),l)
let one x = Cons (x,Nil)
@patrys
patrys / abstract.py
Created September 17, 2010 11:59
Parametrized apps for Django
class AbstractMixin(object):
_classcache = {}
@classmethod
def contribute(cls):
return {}
@classmethod
def construct(cls, *args, **kwargs):
attrs = cls.contribute(*args, **kwargs)
@WebReflection
WebReflection / Function.prototype.notifier.js
Created November 7, 2011 18:08
A Function.prototype method handy to monitor "functions lifecycle"
Function.prototype.notifier = (function () {"use strict";
// (C) WebReflection - Mit Style License
function create(callback) {
function notifier() {
var args = [].slice.call(arguments), output;
if (fire(notifier, "before", callback, this, args, null)) {
try {
output = callback.apply(this, args);
} catch(e) {
fire(notifier, "error", callback, this, args, e);
@asfaltboy
asfaltboy / mousemap_wrapper.py
Last active January 28, 2019 21:21
A simply SublimeText plugin to run a command if matches a selector
"""
A simply SublimeText plugin to run a command if matches a selector.
Usage example - my `Default (OSX).sublime-mousemap`:
[
// for Python we use Anaconda's goto command, for go we use go_guru,
// for others we use built-in goto command
{ "button": "button1", "modifiers": ["ctrl"], "command": "mousemap_wrap",
"press_command": "drag_select", "args": { "commands": [
{
@obmarg
obmarg / gae_workaround.py
Last active January 4, 2017 08:27
Google app engine python issue #7746 workaround
from toolz import concat
def page_iterator(query, page_size=999, **kwargs):
'''
Returns an iterator over pages of a query.
Can be used to work-around the 1000 entity limit in remote_api_shell
:params query: The query we're using.
:params page_size: The page size to return.
:params qwargs: Additional options for fetch_page
@olivergeorge
olivergeorge / pull_mixins.py
Created July 22, 2015 11:04
Mixins to turn Django Rest Framework into a pull api Ref: http://docs.datomic.com/pull.html
import six
from rest_framework import serializers, exceptions, parsers
class PullSerializerMixin(object):
pull_model = None
def __init__(self, *args, **kwargs):
self.pull_model = kwargs.pop('pull_model', self.pull_model)
super(PullSerializerMixin, self).__init__(*args, **kwargs)
@jaysw
jaysw / postmkvirtualenv.sh
Created September 1, 2012 09:02
python virtualenvwrapper and SublimeCodeIntel plugin for Sublime Text integration
#!/usr/bin/env bash
# file: ~/.virtualenvs/postmkvirtualenv
# This hook is run after a new virtualenv is activated.
# setup python interpretor and sitepackages
# for Sublime Text's SublimeCodeIntel plugin.
# codeintel looks in the root of any folder opened via `subl foldername`
# for foldername/.codeintel/config
# it also looks in ~/.codeintel/config
@matthewbelisle-wf
matthewbelisle-wf / gist:3988391
Created October 31, 2012 17:12
App engine cron syntax validation
>>> import sys
>>> sys.path.append('/usr/local/google_appengine/')
>>> from dev_appserver import fix_sys_path
>>> fix_sys_path()
>>> from google.appengine.api.croninfo import GrocValidator
>>> GrocValidator().Validate('invalidsyntax')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/croninfo.py", li
ne 78, in Validate