Skip to content

Instantly share code, notes, and snippets.

View GGrassiant's full-sized avatar
:octocat:
Continuously learning

Guillaume Grassiant GGrassiant

:octocat:
Continuously learning
View GitHub Profile
@dhh
dhh / pagination_controller.js
Last active October 9, 2024 20:23
HEY's Stimulus Pagination Controller
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>
@marekpiechut
marekpiechut / sublime-medium.js
Created July 3, 2020 11:59
Get lazy loading cheap with IntersectionObserver in React
const useLazyMediaLoad = media => {
const [url, setUrl] = useState<?string>(null)
const targetRef = useRef<?HTMLElement>(null)
useEffect(() => {
if (!IntersectionObserver) {
thumbLoader(media).then(setUrl)
} else if (targetRef.current) {
let observer = new IntersectionObserver(
entries =>
import React, { FC } from 'react'
import { SWRConfig } from 'swr'
import axios from 'axios'
import { ProfileContainer } from './ProfileContainer'
import './App.css'
const fetcher = (url: string) =>
axios(url).then(
response =>
/**
* Creating objects with Classes
* Versus objects with prototypes
* Since JavaScript is not a Class-based language
* what is happening behind the class syntax?
*/
let PersonC = class {
constructor(nm, id) {
this.name = nm;
const SSkeletonPulse = styled.div`
display: inline-block;
height: 100%;
width: 100%;
background: ${props =>
props.translucent
? css`linear-gradient(-90deg, #C1C1C1 0%, #F8F8F8 50%, #C1C1C1 100%)`
: css`linear-gradient(-90deg, #F0F0F0 0%, #F8F8F8 50%, #F0F0F0 100%)`};
background-size: 400% 400%;
animation: pulse 1.2s ease-in-out infinite;
@quisido
quisido / solution.js
Created December 12, 2018 13:30
Variable length currying in JavaScript
// Given an array of numbers, if the index is even, add.
// If the index is odd, subtract.
const addSubtractReducer = (total, current, index) =>
(index % 2) === 0 ?
total + current :
total - current;
const addSubtract = x => {
const nums = [ ];
// IntersectionObserver polyfill
import 'intersection-observer'
// *****************************
import React, { Component } from 'react'
export default class ImageLazyLoader extends Component {
state = {
isLoaded: false,
@CodeDraken
CodeDraken / typeof.c
Created September 25, 2018 00:20
js-typeof-soruce
JS_PUBLIC_API(JSType)
JS_TypeOfValue(JSContext *cx, jsval v)
{
JSType type = JSTYPE_VOID;
JSObject *obj;
JSObjectOps *ops;
JSClass *clasp;
CHECK_REQUEST(cx);
if (JSVAL_IS_VOID(v)) { // (1)
@stevecondylios
stevecondylios / contact-form.md
Last active December 23, 2022 07:33
Tutorial: Create and Deploy a Contact Form to Production in Ruby on Rails 5

Create a Contact Form in Rails 5



2021 UPDATE: some parts of this tutorial are now out of date, please use Create a Contact Form in Rails 6 instead. The rails 5 / gmail version remains below for posterity.






This is a complete, step-by-step tutorial showing how to create a fully functional contact form in production in rails 5. Rather than reinvent things, the following borrows from the best available documentation and tutorials (most notably, this tutorial on making a contact form in development). The finished contact form can be viewed here.

@toadkicker
toadkicker / about.html.erb
Last active January 25, 2022 23:56
How to build the simplest static site with Rails (yes I know you can put files in public and call that simpler. This uses the framework)
<p>Hi! I'm an about page. Edit me in views/static_pages/</p>