Skip to content

Instantly share code, notes, and snippets.

View michaelryancaputo's full-sized avatar
🔲

Michael Caputo michaelryancaputo

🔲
View GitHub Profile
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);
@vjo
vjo / meetup_waiting_pos.js
Last active August 1, 2016 17:38
Find your position in Meetup.com waiting list
$("#rsvp-list-waitlist h5")
.map(function(i, el) {return {"pos": i, "name": $(el).text()}})
.filter(function(i, el) {return el["name"].indexOf("Your name") >= 0;});
@killercup
killercup / mongodb.js
Created March 4, 2014 16:15
Mongodb ObjectId Filter for Angular
angular.module('rm.MongoDB', [])
/**
* @method Object ID to Date
* @param {String} objectID The Object ID as String
* @return {Date} Creation Date of ObjectId
*/
.filter("objectIDtoDate", function () {
return function (objectID) {
return new Date(parseInt((""+objectID).substr(0,8), 16)*1000);
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@JeffreyWay
JeffreyWay / tip.sh
Created August 15, 2013 17:51
Ever want to undo everything that you've worked on since the last commit (including adding new files)? Here's a little alias to help with that.
alias gundo='git reset HEAD~ && git clean -df'
@kumarharsh
kumarharsh / Mongo ObjectID to Timestamp
Created May 19, 2013 15:40
A snippet to convert Mongo ObjectID to javascript timestamps, and vice-versa
----- mongo to js ------
timeStamp = parseInt(Mongo.ObjectId().toString().substr(0,8), 16)*1000
date = new Date(timestamp)
-----------------------------
----- js to mongo -----
timestamp = new Date().getTime()/1000
mongoId = new ObjectID(timestamp.toString(16)+1e16)
@nickawalsh
nickawalsh / icons.sass
Last active October 7, 2021 09:38
Auto Hi-res Sprites
@import compass
$icons: sprite-map("icons/*.png")
$icons-hd: sprite-map("icons-hd/*.png")
i
background: $icons
display: inline-block
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
background: $icons-hd
@marcedwards
marcedwards / high-dpi-media.css
Last active November 19, 2023 12:56
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */