Skip to content

Instantly share code, notes, and snippets.

View filosganga's full-sized avatar

Filippo De Luca filosganga

View GitHub Profile
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@mislav
mislav / pagination.md
Created October 12, 2010 17:20
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@samuel
samuel / backup.py
Created November 8, 2010 22:42
A script to automate freezing XFS and locking MongoDB and snapshotting EBS volumes
#!/usr/bin/env python
from __future__ import with_statement
import contextlib
import logging
import os
import sys
import urllib2
from boto.ec2.connection import EC2Connection
@kevinwright
kevinwright / PimpMyFilter.scala
Created October 4, 2011 22:11
Pimpin' + on a T => Either[ERR,T] for easy chaining
class Filters[T] {
//Some boilerplate-busting aliases
type FilterResult = Either[Rejection, T]
type FilterFunc = (T) => FilterResult
//Handy helpers
//Rejection can carry as much info as you wish;
// Filter name, value in error, an exception, etc.
case class Rejection(input: T, msg: String)
@tsabat
tsabat / zsh.md
Last active December 25, 2023 19:16
Getting oh-my-zsh to work in Ubuntu
@stonegao
stonegao / AkkaKafkaMailboxTest.scala
Created May 1, 2012 07:24 — forked from mardambey/AkkaKafkaMailboxTest.scala
Akka 2.0 actors with Kafka backed durable mailboxes.
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.agent.Agent
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.actor.Props
import kafka.utils.Utils
import java.nio.ByteBuffer
@vlfig
vlfig / TestCaseClassInterning.scala
Created September 20, 2012 17:27
Traits to easily make classes intern their instances assuring no duplicates exist at runtime. Don't forget to check your equals and hashCode.
import scala.collection.mutable.WeakHashMap
/**
* Utility traits for classes whose companion objects are to
* intern their instances, never creating repeated objects.
*
* Instances are cached based on their immutable
* arguments, as provided to companion object's {{apply()}}.
*/
@viktorklang
viktorklang / ExecutionContextExecutorServiceBridge.scala
Last active June 27, 2022 11:38
Turning an ExecutionContext to an ExecutorService (or rather and ExecutorService AND an ExecutionContext) using Scala 2.10+
/*
Copyright 2013 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@vmadman
vmadman / logstash-supervisord
Created April 27, 2013 06:48
An example SupervisorD configuration for all three logstash components. Some of it might look obvious, but it took a ton of tweaking to figure it out. (but I might just be dumb)
[program:lss]
process_name=Shipper
command=java -jar /usr/local/logstash/bin/logstash-1.1.9-monolithic.jar agent --config /usr/local/logstash/conf/shipper.conf --log /usr/local/logstash/log/shipper.log
user=logstash
startretries=3
redirect_stderr=true
std_out_logfile=NONE
startsecs=3
environment=HOME="/usr/local/logstash/"
@johnynek
johnynek / twophase.scala
Last active October 2, 2020 22:36
A two-phase commit Transaction Monad. See: http://en.wikipedia.org/wiki/Two-phase_commit_protocol
// Run this with scala <filename>
/**
* A Two-phase commit Monad
*/
trait Transaction[+T] {
def map[U](fn: T => U): Transaction[U] = flatMap { t => Constant(fn(t)) }
def flatMap[U](fn: T => Transaction[U]): Transaction[U] =
FlatMapped(this, fn)