Skip to content

Instantly share code, notes, and snippets.

@Roman2K
Roman2K / gist:984482
Created May 21, 2011 12:32
Integer#multiple_of?
class Numeric
def multiple_of?(*numbers)
zero? || numbers.all? { |n| n.nonzero? && modulo(n).zero? }
end
end
if $0 == __FILE__
require 'test/unit'
class MultipleOfTest < Test::Unit::TestCase
Process: VLC [15477]
Path: /Applications/VLC.app/Contents/MacOS/VLC
Identifier: org.videolan.vlc
Version: 1.3.0-git (1.3.0-git)
Code Type: X86-64 (Native)
Parent Process: launchd [108]
Date/Time: 2011-12-23 01:11:11.538 +0100
OS Version: Mac OS X 10.7.2 (11C74)
Report Version: 9
@Roman2K
Roman2K / gist:1753140
Created February 6, 2012 16:32
Debugging CoffeeScript
#!/bin/bash
file=$1
filename=$(basename "$file")
tmp_filename=${filename%.coffee}.$RANDOM.js
out="/tmp/$tmp_filename"
coffee -s -c < "$file" > "$out" || exit 1
"$EDITOR" "$out" && rm -f "$out"
@Roman2K
Roman2K / node.js
Created September 29, 2012 18:22
Ruby/node encryption/decryption
const crypto = require('crypto');
const PASSWORD = "098f6bcd4621d373cade4e832627b4f6"
, MESSAGE = 'test';
function InvalidSignatureError() {
Error.captureStackTrace(this, this.constructor);
}
function encipher(message, password, callback) {
Misplaced "ensures" in sample code from:
http://railsware.com/blog/2012/11/20/yield-gotcha-in-ruby-blocks/
Always be careful when adding "ensure" statements. Variables used within its
block may not have been assigned if an exception is raised within the "begin"
block. In fact, this mistake is often the result of not bothering with a "begin"
statement altogether
@Roman2K
Roman2K / updatePrices.js
Created January 6, 2014 17:23
Drive > Spreadsheet > Tools > Script editor...
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet().addMenu("Update", [
{name: "Prices", functionName: "updatePrices"}
]);
}
function updatePrices() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getRange('D2');
while (/^...\/...$/.test(cell.getValue())) {
@Roman2K
Roman2K / guard-kill
Created January 31, 2014 14:06
For when Guard doesn't behave after a Ctrl-C (won't exit or worse, leaves session-leader processes in the wild).
#!/usr/bin/env bash
guard_pids() {
ps ax | egrep ' guard (master|worker)' | while read pid _; do
echo $pid
done
}
kill_guard() {
pids=$(guard_pids)
#!/usr/bin/env bash
exec coffee -cs < "$1" > /dev/null
var url = 'http://www.unicreditbank.si/tecajna_lista/?t=1&id_menu=&language=ENG';
var rate = UrlFetchApp.fetch(url).getContentText().replace(/\s+/g, '').match(/>USD<\/td.*?>1,.*?>(1,\d+)/)[1];