Skip to content

Instantly share code, notes, and snippets.

@ayushn21
ayushn21 / Gemfile
Created November 21, 2022 20:30
The Gemfile for the app built in The Rails and Hotwire Codex (https://railsandhotwirecodex.com)
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.1"
gem "rails", "~> 7.0.0"
gem "pg", "~> 1.1"
gem "puma", "~> 5.0"
gem "jsbundling-rails", "~> 0.1.0"
gem "turbo-rails", "~> 1.3.0"
@ayushn21
ayushn21 / element_observer.js
Created May 31, 2021 13:55
A wrapper around MutationObserver to observe an element's tree for nodes matching a selector being added or removed
export class ElementObserver {
constructor(element, selector, delegate) {
this.element = element
this.selector = selector
this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations))
this.delegate = delegate
}
start() {
this.mutationObserver.observe(this.element, { childList: true, subtree: true })
@ayushn21
ayushn21 / TemplateImageView.swift
Created December 25, 2015 15:18
A workaround for Xcode's flaky handling for images as templates. Just make this the class for your template images and set the colour in the storyboard and everything will just work :)
class TemplateImageView: UIImageView {
@IBInspectable var color: String?
override init(frame: CGRect) {
super.init(frame: frame)
self.setUp()
}
override init(image: UIImage?) {
@ayushn21
ayushn21 / UILabel+AutoShrink.m
Last active April 18, 2017 03:50
A small category on UILabel to allow for auto shrinking of text for multi line UILabels. Based on the implementation described here: http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/
@implementation UILabel (AutoShrink)
- (void)resizeTextToFit
{
int currentFontSize = (int) self.font.pointSize;
int minimumFontSize = (int) (self.minimumScaleFactor*currentFontSize);
UIFont *font = self.font;
for(int i = currentFontSize; i > minimumFontSize; i=i-2)
@ayushn21
ayushn21 / ANRotateView.m
Last active August 29, 2015 14:14
A simple method to rotate iOS Views more than 360 degrees
// Extra declarations for the method
#define degreesToRadians(degrees) ((degrees)/180.0*M_PI)
typedef NS_ENUM(NSUInteger, Direction)
{
Clockwise,
Anticlockwise
};
//////////////////////////////////////////