Skip to content

Instantly share code, notes, and snippets.

View mariorcardoso's full-sized avatar

Mario Cardoso mariorcardoso

View GitHub Profile
const generateImageWithCanvas = (
track: MediaStreamTrack,
videoElem: HTMLVideoElement
) => {
const canvas = document.createElement("canvas");
const { width, height } = track.getSettings();
canvas.width = width || 100;
canvas.height = height || 100;
export const imageCapture = async ({
videoRef,
}: ImageCaptureInput): Promise<string | undefined> => {
try {
const videoElem = videoRef.current;
if (!videoElem) throw Error("Video HTML element not defined");
let mediaStream = videoElem.srcObject as MediaStream;
if (!mediaStream) throw Error("Video MediaStream not defined");
export const imagePreview = async ({
videoRef,
}: ImagePreviewInput): Promise<MediaStream | undefined> => {
try {
const videoElem = videoRef.current;
if (!videoElem) throw Error("Video HTML element not defined");
videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia();
return videoElem.srcObject;
export const ScreenshotTool = () => {
...
return (
<Fragment>
<div>
<button disabled={canCapture} onClick={startImagePreview}>
Preview
</button>
<button disabled={!canCapture} onClick={captureImageInPreview}>
@mariorcardoso
mariorcardoso / macossetup.sh
Last active August 30, 2023 15:02
macOS fresh install setup
# Xcode Command-line Tools
xcode-select --install
# Productivity
brew install --cask rectangle
brew install notion
# Finder settings
# Show hidden files
defaults write com.apple.finder AppleShowAllFiles TRUE
class DateRange < Value.new(:start_date, :end_date)
def include_date?(date)
date >= start_date && date <= end_date
end
def include_date_range?(date_range)
start_date <= date_range.start_date && end_date >= date_range.end_date
end
def overlap_date_range?(date_range)
> room_1 = Room.create(degrees: 10)
> room_2 = Room.create(degrees: 20)
> room_3 = Room.create(degrees: 30)
> room_1.temperature.cold?
=> true
> room_1.temperature.hot?
=> false
> [room_1.temperature, Temperature.new(20), room_3.temperature, room_2.temperature].sort
=> [#<Temperature:0x007fe194378840 @degrees=10>, #<Temperature:0x007fe194378818 @degrees=20>, #<Temperature:0x007fe1943787c8 @degrees=20>, #<Temperature:0x007fe1943787f0 @degrees=30>]
> [room_1.temperature, Temperature.new(20), room_3.temperature, room_2.temperature].uniq
> event = Event.create(name: 'Ruby conf', start_date: Date.today, end_date: Date.today + 1.days)
> event.date_range
=> #<DateRange:0x007fd8760c2690 @start_date=Tue, 06 Jun 2017, @end_date=Fri, 07 Jun 2017>
> event.date_range.include_date?(Date.today)
=> true
> event.date_range.include_date_range?(DateRange.new(Date.today, Date.today + 2.days))
=> false
> event.date_range.include_date_range?(DateRange.new(Date.today, Date.today + 1.days))
=> true
class Size
SIZES = %w(small medium big)
attr_reader :size
def initialize(size)
@size = size
end
def self.to_select
SIZES.map{|c| [c.capitalize, c]}
class Event < ActiveRecord::Base
SIZE = %w(
small
medium
big
)
end