Skip to content

Instantly share code, notes, and snippets.

View nicohaemhouts's full-sized avatar

Nico Haemhouts nicohaemhouts

  • Sydney, Australia
View GitHub Profile
@nicohaemhouts
nicohaemhouts / _.md
Last active August 29, 2015 14:26
Scrolling line chart
@nicohaemhouts
nicohaemhouts / _.md
Last active August 29, 2015 14:26
Updating Area Chart
@nicohaemhouts
nicohaemhouts / _.md
Last active August 29, 2015 14:27
Random Increasing Line Chart
git tag archive/<your-branch> <your-branch>
git push --tags
git push -d origin <your-branch>
git branch -D <your-branch>
/* Using GeometryReader to find out the width of the parent is problematic when the parent does not have a height and depends on its children to give it height, e.g. VStack, ScrollView, etc GeometryReader takes up all the space it can get but if the parent has no height then GeometryReader will simply not have a height and your view will not render properly. ParentWidthReader uses a widely used workaround using PreferenceKey and a GeometryReader as a background thus bypassing the height problem.
*/
import SwiftUI
struct ParentWidthReader<Content>: View where Content: View {
typealias ContentBuilder = (CGFloat) -> Content
@State var width: CGFloat = .infinity
let content: ContentBuilder
@nicohaemhouts
nicohaemhouts / Limit-the-number-of-lines-in-a-textarea.markdown
Last active March 18, 2024 22:01
Limit the number of lines in a textarea

Limit the number of lines in a textarea

This limits the number of lines of any textarea that has the attribute 'data-limit-rows' set to 'true'. The limit is the 'rows'-attribute of the textarea.

To know how many lines have been entered you have to look at the number of newline characters (\n) in the text. You could do this by splitting text on the newline character, and looking at the length of the resulting array: i.e. myText.split(/\n/g).length; This would work fine in every browser, except for one special case in Internet Explorer 8, whereby the user hits the enter key several times in a row, thus producing empty lines. In this case Internet Explorer 8 excludes all empty values from the resulting array, ie those places where the delimiters appear next to each other. The result is that the usr can enter more lines of text than permitted. This is probably also true for Internet Explorer versions lower than 8, but I didn't check.

To know which key was pressed it's b