Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Edison Yap edisonywh

🎯
Focusing
View GitHub Profile
View Calendar.tsx
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 Apr 2, 2021
Suggestion Component (For use with Backoffice)
View suggestion_component.ex
defmodule SlickWeb.NewsletterSuggestionComponent do
use SlickWeb, :live_component
def mount(socket) do
socket =
socket
|> assign(:suggestions, [])
|> assign(:picked, nil)
{:ok, socket}
View ruby_array_memory.rb
# 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 Sep 20, 2018
Pings `ozbargain.com.au` and send a notification if a keyword matches
View nightwatch.rb
require 'httparty'
require 'pry'
require 'nokogiri'
require 'terminal-notifier'
class FeedService
attr_accessor :url
attr_accessor :keyword
@edisonywh
edisonywh / pre-commit
Last active Aug 27, 2018
Run Rubocop in Git's pre-commit hook
View pre-commit
```
#!/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