Skip to content

Instantly share code, notes, and snippets.

View hassanrbh's full-sized avatar
🎓
busy

Hassan Tarif hassanrbh

🎓
busy
View GitHub Profile
@hassanrbh
hassanrbh / whereable.rb
Created February 18, 2022 15:58 — forked from searls/whereable.rb
The initial implementation of a Whereable query filter for KameSame.
class Whereable
def initialize(where:, model: Item, ranking_conditions: [], valid: true, data_source: nil)
@model = model
@where = where
@data_source = data_source
@ranking_conditions = ranking_conditions
@valid = valid
end
def valid?
@hassanrbh
hassanrbh / gitstats.sh
Created February 10, 2022 15:09 — forked from xeoncross/gitstats.sh
Git - calculate how many lines of code were added/changed by someone
# Run this in the project repo from the command-line
# http://stackoverflow.com/a/4593065/99923
git log --shortstat --author "Xeoncross" --since "2 weeks ago" --until "1 week ago" | grep "files changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
@hassanrbh
hassanrbh / binary.rb
Created January 31, 2022 13:08 — forked from xfbs/binary.rb
Ruby: convert string to binary form and back (one liners
# not the most efficient way,
# but you get the idea.
str = "meow"
# convert string to binary
bin = str.bytes.map{|d| d.to_s(2)}.map{|b| b.rjust(8, '0')}.join
puts bin
# and convert it back to a string
class Node
attr_reader :key
attr_accessor :val, :next, :prev
def initialize(key = nil, val = nil)
@key = key
@val = val
@next = nil # the next value is pointing to nil
@prev = nil
end