View thread-pool.rb
require 'thread' # for Mutex: Ruby doesn't provide out of the box thread-safe arrays
class ThreadPool
def initialize(max_threads = 10)
@pool = SizedQueue.new(max_threads)
max_threads.times{ @pool << 1 }
@mutex = Mutex.new
@running_threads = []
end
View human-numbers.cpp
/*
* A simple way to format numbers as human readable strings.
* E.g., 123456789 ==> 123 million
*
* Written by Christian Stigen Larsen
* http://csl.sublevel3.org
*
* Placed in the public domain by the author, 2012
*/
View feeds.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
"""
Tools to extract feed links, test if they are valid and parse them
with feedparser, returning content or a proper error.
"""
View switch_touchscreen.sh
#! /bin/bash
# switch_touchscreen.sh
# https://ubuntuforums.org/showthread.php?t=2100744
# Use `xinput --list` to list all devices and find your touchscreen
# sudo chmod a+x switch_touchscreen.sh
DEVICE="Atmel Atmel maXTouch Digitizer"
STATUS=`xinput list-props "$DEVICE" | grep 'Device Enabled' | sed 's/.*\([0-9]\)$/\1/'`
if [ "$STATUS" = "1" ]
View switch_touchscreen.sh
#! /bin/bash
# switch_touchscreen.sh
# https://ubuntuforums.org/showthread.php?t=2100744
# sudo chmod a+x switch_touchscreen.sh
DEVICE="Atmel Atmel maXTouch Digitizer"
STATUS=`xinput list-props "$DEVICE" | grep 'Device Enabled' | sed 's/.*\([0-9]\)$/\1/'`
if [ "$STATUS" = "1" ]
then
View game.rb
require 'ostruct'
require 'irb'
# Some monkey patch to add colorized output in console
class String
COLORS_CODE = {
red: 31,
green: 32,
yellow: 33,
blue: 34,
View yield.js
function* process() {
console.log('Start process 1');
console.log('Pause process2 until call next()');
yield;
console.log('Resumed process2');
console.log('Pause process3 until call next()');
yield;
View sequel_en.yml
"en":
"sequel":
"validation_errors":
"exact_length": "is not %{exact} characters"
"format": "is invalid"
"includes": "is not in range or set: %{set}"
"integer": "is not a number"
"length_range": "is too short or too long. Range: %{range}"
"max_length": "is longer than %{max} characters"
"max_length_nil": "is not present"
View gist:a8cec73a7d6b1cad064d8716fc2990d2
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
View wtf.js
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2