Skip to content

Instantly share code, notes, and snippets.

View davidnagli's full-sized avatar
🚀
Changing the world

David Nagli davidnagli

🚀
Changing the world
View GitHub Profile
@tnarla
tnarla / page.tsx
Created February 2, 2024 20:35
Valentine website
"use client";
import { useState } from "react";
export default function Page() {
const [noCount, setNoCount] = useState(0);
const [yesPressed, setYesPressed] = useState(false);
const yesButtonSize = noCount * 20 + 16;
const handleNoClick = () => {
setNoCount(noCount + 1);
@davidnagli
davidnagli / useFirebaseDemo.js
Created October 29, 2018 20:25
Dead Simple Firebase React Hook
//useFirebase.js
import firebase from 'firebase';
import {useState, useEffect} from 'react';
export function useFirebase(refName){
const [state, setState] = useState(null);
useEffect(()=>{
firebase.database().ref(refName).on('value', snapshot => {
@davidnagli
davidnagli / cdup.js
Created January 14, 2018 21:52
cdup-js : count duplicates in a javascript array (find the count of each unique element in an array) with this simple, easy, and FAST one liner
// Readable version:
array.reduce((countsMap, item) => countsMap.set(item, countsMap.get(item) + 1 || 1), new Map)
// Minified version:
array.reduce((a,b)=>a.set(b,a.get(b)+1||1),new Map)
@raecoo
raecoo / array_dupplicate_counter.js
Created December 7, 2012 02:42 — forked from ralphcrisostomo/array_dupplicate_counter.js
Javascript: Count duplicates in an array
/**
Problem:
You have a javascript array that likely has some duplicate values and you would like a count of those values.
Solution:
Try this schnippet out.
*/
@ralphcrisostomo
ralphcrisostomo / array_dupplicate_counter.js
Created July 19, 2012 07:43
Javascript: Count duplicates in an array
/**
Problem:
You have a javascript array that likely has some duplicate values and you would like a count of those values.
Solution:
Try this schnippet out.
*/