This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def date_in_danish_time(date_time) | |
date_array = | |
date_time.strftime("%Y %m %d").split.map { |string| Integer(string, 0) } | |
danish_date = Date.new(*date_array).in_time_zone("Copenhagen") | |
# extracting offset from the date will help us in also taking care of Daylight Saving | |
danish_date_offset = danish_date.formatted_offset | |
date_time_array = | |
date_time | |
.strftime("%Y %m %d %H %M %S") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Maybe there's a way to support ActiveSupport::Concern's dependencies too? | |
# Although this doesn't use the module hierarchy, so `prepend` can't work. | |
class Concern < Module | |
def initialize(&block) = @block = block | |
def included(klass) = klass.class_eval(&@block) | |
end | |
module Kernel | |
def Concern(...) = Concern.new(...) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%# app/views/layouts/application.html.erb %> | |
... | |
<%= javascript_include_tag "locales/#{I18n.locale}", nonce: true %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Builds an SQL insert query for a given record | |
# | |
# @param record [ActiveRecord::Base] Record used to build the SQL insert query | |
# @return [String] SQL insert query | |
def build_insert_query(record) | |
columns = record.class.columns.reject { |col| col.name == record.class.primary_key } | |
values = columns.map { |col| record[col.name] } | |
insert_manager = Arel::InsertManager.new | |
insert_manager.into(record.class.arel_table) | |
insert_manager.insert(columns.zip(values)).to_sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "phlex" | |
end | |
require "phlex/testing/view_helper" | |
include Phlex::Testing::ViewHelper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { options } from "preact"; | |
import { Signal } from "@preact/signals"; | |
// Add `bind:value` to JSX types | |
declare global { | |
namespace preact.createElement.JSX { | |
interface HTMLAttributes { | |
"bind:value"?: Signal<string | string[] | number | undefined>; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Measure = Data.define(:amount, :unit) do | |
def diff(other) | |
raise ArgumentError.new("other must be same class") unless other.is_a?(self.class) | |
members.inject({}) do |memo, key| | |
thisVal, otherVal = send(key), other.send(key) | |
memo[key] = [thisVal, otherVal] unless thisVal == otherVal | |
memo | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Packer | |
# A special packer class for globally identifiable objects. It takes a global ID and packs it as a String, then rehydrates it as a GlobalID lookup. | |
class GloballyIdentifiable | |
def self.from_pack(uri) | |
GlobalID::Locator.locate(uri) | |
end | |
def initialize(identifiable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Turn all HTML <a> elements into client side router links, no special framework-specific <Link> component necessary! | |
// Example using the Next.js App Router. | |
import { useRouter } from 'next/navigation'; | |
import { useEffect } from 'react'; | |
function useLinkHandler() { | |
let router = useRouter(); | |
useEffect(() => { | |
let onClick = e => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object::Proxy < SimpleDelegator | |
def initialize(object, **values) | |
super(object) | |
@values = values | |
end | |
def method_missing(name, ...) | |
@values.fetch(name) { super } | |
end | |
end |
NewerOlder