Skip to content

Instantly share code, notes, and snippets.

View styd's full-sized avatar
🏡
Work From Home

Adrian Setyadi styd

🏡
Work From Home
  • Jiffy
  • Bekasi, Indonesia
  • 18:55 (UTC +07:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am styd on github.
  • I am styd (https://keybase.io/styd) on keybase.
  • I have a public key ASAnzyUjJAHKFwcivUpUxNg_jSZWczIGOt0DN1QJIpvx7wo

To claim this, I am signing this object:

@styd
styd / ruby-to-rust-cheat-sheet.md
Last active September 4, 2024 04:49 — forked from carols10cents/ruby-to-rust-cheat-sheet.md
Ruby to Rust Cheat Sheet

Ruby to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in Ruby and Rust so that programmers most comfortable with Ruby can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables

Ruby:

@styd
styd / Palindrome.rb
Last active November 16, 2017 09:54
Strict and non-strict palindrome. Default is not strict.
#!/usr/bin/env ruby
class String
def palindrome?(strict = false)
return true if length.zero? || length == 1
i = -1
j = length
length.times do
loop do
i += 1
break if strict || self[i] =~ /[A-z0-9]/
@styd
styd / Josephus.rb
Last active November 13, 2017 10:09
Josephus Problem
#!/usr/bin/env ruby
#
# Josephus Problem
# https://www.youtube.com/watch?v=uCsD3ZGzMgE
#
def who_will_live?(n)
a = 1
begin
a <<= 1
end until a > n
@styd
styd / Prime.rb
Last active October 12, 2017 10:50
A stupid job post on Upwork asking to write this. An easy US$ 8 I missed (didn't get the job). :(
#!/usr/bin/env ruby
print "Enter a number: "
input = gets.to_i
divisors = []
(2...input).each do |i|
divisors << i if input % i == 0
end
if divisors.empty?
puts "#{input} is a prime number"
else