Skip to content

Instantly share code, notes, and snippets.

View onedebos's full-sized avatar

Adebola Adeniran onedebos

View GitHub Profile
import { useState } from "react";
import { useRouter } from "next/router";
function MyApp({ Component, pageProps }) {
const [sender, setSender] = useState("");
const router = useRouter();
const handleLogin = (e) => {
e.preventDefault();
router.push("/chat");
@onedebos
onedebos / _app.js
Created March 7, 2021 12:48
/pages/_app.js
import '../styles/globals.css'
import Pusher from 'pusher-js'
function MyApp({ Component, pageProps }) {
const {key, cluster} = process.env
const pusher = new Pusher(key, {
cluster
});
@onedebos
onedebos / index.js
Last active March 8, 2021 21:09
pages/api/pusher.js
import Pusher from "pusher";
export const pusher = new Pusher({
appId: process.env.app_id,
key: process.env.key,
secret: process.env.secret,
cluster: process.env.cluster,
useTLS: true,
});
@onedebos
onedebos / mailing_list_controller.rb
Last active November 27, 2020 11:16
How to create a mailing list in Mailchimp with Ruby on Rails
class MailingListController < ApplicationController
def addUser
# Setup the keys needed to access Mailchimp's API
dc = 'us13'
unique_id = "f1ff300381"
url = "https://#{dc}.api.mailchimp.com/3.0/lists/#{unique_id}/members"
api_key = "YOUR_API_KEY"
# You need to pass the status:subscribed field to ensure the user is subscribed
user_details = {
import { parseCookies } from "../helpers/"
export default function HomePage({ data }) {
return (
<>
<div>
<h1>Homepage </h1>
<p>Data from cookie: {data.user}</p>
</div>
</>
)
@onedebos
onedebos / index.js
Created October 29, 2020 10:57
Parsing cookies helper
// helpers/index.js
import cookie from "cookie"
export function parseCookies(req) {
return cookie.parse(req ? req.headers.cookie || "" : document.cookie)
}
import { CookiesProvider } from "react-cookie"
export default function MyApp({ pageProps }) {
return (
<CookiesProvider>
<Component {...pageProps} />
</CookiesProvider>
)
}
// pages/login.js
import { useCookies } from "react-cookie"
const Login = () => {
const [cookie, setCookie] = useCookies(["user"])
const handleSignIn = async () => {
try {
const response = await yourLoginFunction(username) //handle API call to sign in here.
const data = response.data
setCookie("user", JSON.stringify(data), {
path: "/",
import React, {useRef} from 'react'
const UseRefEx = () =>{
let usernameRefs = useRef([]);
usernameRefs.current = [0,0,0,0].map(
(ref, index) => usernameRefs.current[index] = React.createref()
)
@onedebos
onedebos / Form.js
Last active July 6, 2020 10:41
A snippet for creating netlify forms using Gatsby
import React, { useState } from "react"
const encode = data => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&")
}
const Form = () => {
const [submitted, setSubmitted] = useState("")