This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Or: require 'facets/enumerable/find_yield' | |
module Enumerable | |
def map_detect | |
self.each do |member| | |
if (result = yield(member)) | |
return result | |
end | |
end | |
nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Simple monitoring using a finite state machines | |
set -e -u -o pipefail | |
# Print debug output to standard error | |
debug() { | |
echo "[${FUNCNAME[1]}] $@" >&2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pure functional implementation of D'Hondt method | |
from itertools import islice, count | |
from collections import Counter | |
from heapq import merge | |
def percentage(numerator, denominator): | |
return 100.0 * numerator / denominator | |
def take(n, it): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Importer | |
CODES = {:header, "00F", :data => "00I"} | |
def self.import_products(fileobj) | |
fileobj.lines.each_slice(4).map do |group_lines| | |
type, *data_lines = group_lines.map(&:strip) | |
case type | |
when CODES[:header] | |
# what to do/return here? | |
when CODES[:data] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.annotation.Target; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.ElementType; | |
import java.lang.reflect.Method; | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@interface MyAnnotation { | |
String name() default ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return sum of numbers in array xs */ | |
function sum(xs) { | |
return xs.reduce(function(a, b) { return a + b }, 0); | |
} | |
/* Return true if string s is a valid DNI */ | |
function validateDNI(s) { | |
var control_letters = 'TRWAGMYFPDXBNJZSQVHLCKE'; | |
var regexp = /^[\dKLMXYZ]\d{7}[A-Z]$/; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import signal | |
from PyQt4 import QtCore, QtGui, QtWebKit | |
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkCookieJar, QNetworkCookie | |
class ExtendedNetworkCookieJar(QNetworkCookieJar): | |
def mozillaCookies(self): | |
""" | |
Return all cookies in Mozilla text format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# Download lecture videos of courses from Coursera (http://www.coursera.org). | |
# | |
# Install requirements: | |
# | |
# $ gem install curb trollop nokogiri capybara ruby-progressbar | |
# | |
# Example -- Download all video lectures of courses "Calculus: Single Variable" | |
# and "Introduction to Astronomy": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara' | |
# $ xvfb-run rspec -f documentation chrome-extension_spec.rb | |
# | |
# ./myext -- Directory containing the unpacked extension | |
class ChromeBrowser | |
include Capybara::DSL | |
def initialize(chrome_flags = {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es"> | |
<head> | |
<title>Testing DataTable/ColOrder with async call</title> | |
<script src="http://code.jquery.com/jquery-1.12.4.js"></script> | |
<script src="http://nightly.datatables.net/js/jquery.dataTables.min.js"></script> | |
<script src="http://nightly.datatables.net/colreorder/js/dataTables.colReorder.js"></script> | |
<script> | |
$(document).ready(function() { | |
var table = $('#example').DataTable({ |