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 'json' | |
require 'uri' | |
require 'csv' | |
# too bad we lack variable size lookbehind | |
bytes_re = /((?:\\\\)+|[^\\])(?:\\u[0-9a-f]{4})+/ | |
friends_txt = File.read('friends.json').gsub(bytes_re) do |bad_unicode| | |
$1 + eval(%Q{"#{bad_unicode[$1.size..-1].gsub('\u00', '\x')}"}).to_json[1...-1] | |
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
INDENT_SIZE = 2 | |
def pretty_jsonify(struct, indent=0) | |
case struct | |
when Array | |
"[\n" + indent_str("", indent+INDENT_SIZE) + | |
struct.map { |value| | |
pretty_jsonify(value, indent+INDENT_SIZE) | |
}.join(",\n#{indent_str('', indent+INDENT_SIZE)}") + |
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
# https://www.jdoodle.com/execute-ruby-online/ | |
def amicable?(int1, int2) | |
sum_proper_divisors(int1) == int2 && sum_proper_divisors(int2) == int1 | |
end | |
def sum_proper_divisors(num) | |
(1..num/2).select { |i| | |
num%i == 0 | |
}.sum |
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
@Grapes([ | |
@Grab(group='org.gperfutils', module='gbench', version='[0.4,)'), | |
@Grab(group='org.apache.commons', module='commons-lang3', version='[3.7,)'), | |
@Grab(group='joda-time', module='joda-time', version='[2.9.9,)') | |
]) | |
/** | |
* Java 8 DateTimeFormatter | |
*/ | |
import java.util.Date; |
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
[Unit] | |
Description=xmr-stak miner | |
After=syslog.target network.target | |
[Service] | |
Type=simple | |
# interesting info about starting as regular user: https://bbs.archlinux.org/viewtopic.php?id=162297 | |
User=username | |
LimitMEMLOCK=256M | |
EnvironmentFile=-/etc/sysconfig/xmr-stak |
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
function _shell_char { | |
if [ "$_EXIT_CODE" -eq 0 ]; then | |
#printf "%s" "$" | |
printf "$RED$shellchar$RESET" | |
else | |
# printf "$RED$FancyX$RESET" | |
printf "$RED$collision$RESET" | |
fi | |
} |
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
def dump_config(object = Rails.application.config.class.class_variable_get(:@@options)) | |
case object | |
when Array | |
object.map { |v| dump_config(v) } | |
when Hash | |
Hash[ object.map { |key, value| [key, dump_config(value)] } ] | |
when TrueClass, FalseClass, Numeric | |
object | |
else | |
object.to_s |
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
# echo server | |
Socket.udp_server_loop(4444) do |data, src| | |
src.reply data | |
end | |
# client | |
addr = Socket.sockaddr_in(4444, "localhost") | |
socket = Socket.new(:INET, :DGRAM) | |
begin | |
socket.send("hello\n", 0) |
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 "rack" | |
def pp(hash) | |
hash["HTTP_ACCEPT"].include?("text/html") ? pp_html(hash) : pp_plain(hash) | |
end | |
def pp_plain(hash) | |
hash.map {|key,value| "#{key}: #{value}"}.sort.join("\n") | |
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
require 'cucumber/core/filter' | |
# put inside features/support/ | |
class PrintOnlyCukeFilter < Cucumber::Core::Filter.new | |
def test_case(test_case) | |
announce | |
print_file_for(test_case) | |
end | |
private |