Skip to content

Instantly share code, notes, and snippets.

View sjmog's full-sized avatar
🤠
well howdy there

Sam Morgan sjmog

🤠
well howdy there
View GitHub Profile
// An implementation of https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas/ in React
import React, { useRef } from 'react'
const AutoGrowingTextArea = props => {
const grower = useRef(null);
return(
<div className="AutoGrowingTextArea" ref={grower}>
<textarea
@sjmog
sjmog / example-misconception-remedy.md
Last active April 22, 2020 10:06
Misconception: Parameter names and argument names must be the same

Misconception: "Parameter names and Argument names must be the same"

True or false: "parameter names and argument names must be the same"?

Play with the following examples: changing the names of the parameters and the arguments.

As always, try to have a hypothesis for what will happen before you make a change.

Ruby Example

@sjmog
sjmog / todo.rb
Created January 8, 2019 13:20
There's something wrong with this code, which means `print_selected` doesn't work. What is it?
class Todo
def initialize(items)
@items = items
end
def print
print @items.join("\n")
end
def print_selected(index)
# why do we do this?
# (demonstrate working with the object and how nice it is)
# (then talk about the idea of different "layers" in software and how we want each "layer" to be self-contained: Ruby in the MVC!)
def self.create(url:, title:)
return false unless is_url?(url)
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'bookmark_manager_test')
else
connection = PG.connect(dbname: 'bookmark_manager')
@sjmog
sjmog / cbl_template.md
Created September 15, 2015 13:27
A template for CBL challenges.
def thing
p "I am great"
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Photos with Friends!</title>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script>
/**
* This is the getPhoto library
*/
@sjmog
sjmog / App.js
Created October 11, 2013 19:48 — forked from ankurkaushal/App.js
App.ProjectController = Ember.ArrayController.extend({
)};
App.Project = App.Model.extend({
id : null,
projectname : null,
projectdesc : null,
projectbudget : null
});
@sjmog
sjmog / gist:4677490
Created January 30, 2013 21:53
A nice little notepad app. Waiting for someone to use HTML5 data storage! Designed so entire code can be posted in to URL bar with 'data:text/html, ' in front. No need to host!
<html>
<head>
<style type="text/css">
html { height: 100%; width:100%; background: #FAFAF0;}
.bodydiv {
-webkit-box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.3);
margin: 0 auto;
padding: 0;