This file contains hidden or 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
| # This version works with files and urls. For URLs, it only downloads the chunks | |
| # of the file neccessary to calculate the hash. | |
| # | |
| # Author: Dan Milne | |
| require "net/http" | |
| require "uri" | |
| module Moviehash | |
| class Error < StandardError; end |
This file contains hidden or 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/env ruby | |
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'json' | |
| gem 'sys-filesystem' | |
| end |
This file contains hidden or 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 valid_json?(string) | |
| result = JSON.parse(string) | |
| result.is_a?(Hash) || result.is_a?(Array) | |
| rescue JSON::ParserError, TypeError | |
| false | |
| end | |
| def valid_json(string, default: []) | |
| result = JSON.parse(string) |
This file contains hidden or 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/env ruby | |
| require 'open-uri' | |
| require 'nokogiri' | |
| VERSION = 0.1 | |
| def getter(url) | |
| URI.open(url, "User-Agent" => "Curlr/#{VERSION}") | |
| rescue OpenURI::HTTPError => e | |
| e.io |
This file contains hidden or 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://stackoverflow.com/questions/1078347/rails-is-there-a-rails-trick-to-adding-commas-to-large-numbers | |
| an_integer.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse | |
| an_int_or_float.to_s.split(".").then {|a| a[0] = a[0]&.reverse&.gsub(/(\d{3})(?=\d)/, '\\1,')&.reverse; a[1].nil? ? a[0] : a[0] + '.' + a[1] } |
This file contains hidden or 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 select_items(count:, items:) | |
| items.lazy.select { |item| item.matchs?(/some filter/ }.take(count).to_a | |
| end | |
| # Other example : https://stackoverflow.com/questions/34787811/short-cutting-version-of-select-for-no-more-than-n-matches |
This file contains hidden or 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 tick args | |
| player = {x: 576, y: 280, w: 20, h: 20, path: 'sprites/circle/red.png'} | |
| args.outputs.sprites << { **player,angle: angle_to_mouse(player, args) } | |
| end | |
| def angle_to_mouse(player, args) | |
| args.geometry.angle_to(player, [args.mouse.x, args.mouse.y]) | |
| end |
This file contains hidden or 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
| {"prefix":"0","value":"English","value_type":"Language area"} | |
| {"prefix":"1","value":"English","value_type":"Language area"} | |
| {"prefix":"2","value":"French","value_type":"Language area"} | |
| {"prefix":"3","value":"German","value_type":"Language area"} | |
| {"prefix":"4","value":"Japan","value_type":"National"} | |
| {"prefix":"5","value":"former USSR","value_type":"Regional"} | |
| {"prefix":"7","value":"China","value_type":"National"} | |
| {"prefix":"65","value":"Brazil","value_type":"National"} | |
| {"prefix":"80","value":"Czechoslovakia","value_type":"Regional"} | |
| {"prefix":"81","value":"India","value_type":"National"} |
This file contains hidden or 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/env ruby | |
| require 'open-uri' | |
| # From https://www.eff.org/dice | |
| count = ARGV[0]&.to_i || 6 | |
| total = ARGV[1]&.to_i || 3 | |
| dice = URI.open("https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt").read.split("\n").map(&:split).to_h |
This file contains hidden or 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 Person | |
| def initialize(name) | |
| @name = name | |
| end | |
| def greet | |
| puts "Hello #{@name}" | |
| end | |
| end | |
| dan = Person.new('Dan') |