Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View edisonywh's full-sized avatar
🎯
Focusing

Edison Yap edisonywh

🎯
Focusing
View GitHub Profile
import React, { useMemo, useState } from "react";
import { format, addDays, startOfWeek, endOfWeek, startOfMonth, endOfMonth, isSameMonth, addMonths, subMonths, parseISO, Interval, isFuture, getTime, isToday, isSameDay } from "date-fns";
import { classNames, isoToUtc } from "../Shared/utils";
import { Habit, HabitType, Progress, Streak, Entry } from "../Shared/types";
import { isWithinInterval } from "date-fns/esm";
import CircularProgressBar from "./CircularProgressBar";
type Prop = {
habit: Habit,
@edisonywh
edisonywh / suggestion_component.ex
Created April 2, 2021 14:53
Suggestion Component (For use with Backoffice)
defmodule SlickWeb.NewsletterSuggestionComponent do
use SlickWeb, :live_component
def mount(socket) do
socket =
socket
|> assign(:suggestions, [])
|> assign(:picked, nil)
{:ok, socket}
require 'objspace'
class Foo
def self.memo_hash
@_memo_hash ||= begin
Hash.new(100)
end
end
end
# Note: This is pretty badly written code, I just wrote it as a quick proof for https://dev.to/edisonywh/how-arrays-work-the-way-arrays-work-3bpg
# To get the growth rate of the array, just look at the jump in memory bytes after every copy. You can see that it's about 1.5~
require 'objspace' # Require this for additional ObjectSpace methods
def memory_calculator
array = Array.new
result = {}
100.times do |i|
@edisonywh
edisonywh / nightwatch.rb
Last active September 20, 2018 17:42
Pings `ozbargain.com.au` and send a notification if a keyword matches
require 'httparty'
require 'pry'
require 'nokogiri'
require 'terminal-notifier'
class FeedService
attr_accessor :url
attr_accessor :keyword
@edisonywh
edisonywh / pre-commit
Last active April 15, 2024 22:58
Run Rubocop in Git's pre-commit hook
```
#!/bin/sh
echo "\nRunning rubocop 🚓 💨 💨 💨\n"
declare -a ERRORS=()
for file in $(git diff --cached --name-only | grep -E '.rb')
do
ERRORS+=("$(rubocop $file | grep -e 'C:' -e 'E:')")
done