Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@joshuacerbito
joshuacerbito / useScroll.js
Last active January 8, 2024 13:44
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { scrollX, scrollY, scrollDirection } = useScroll();
*/
import { useState, useEffect } from "react";
export function useScroll() {
const [lastScrollTop, setLastScrollTop] = useState(0);
@rbk
rbk / rest-api-doc-example.md
Last active June 7, 2019 19:40
Example of REST API documentation (Based on Twitter, 2018)
@paulera
paulera / burndown.html
Last active July 15, 2021 07:31
Burndown chart built using Chart.js
<html>
<!-- See live at https://codepen.io/paulera/pen/ejGKEr -->
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
/**
* Sum elements of an array up to the index provided.
*/
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
NSString *url = @"http://localhost:5000/api/updates/";
if(checksum){
url = [NSString stringWithFormat:@"%@?checksum=%@", url, checksum];
}
[request setURL:[NSURL URLWithString:url]];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *err) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
@JoeSz
JoeSz / isElementInViewport.js
Last active November 5, 2021 09:14
isElementInViewport and isElementPartiallyInViewport
/*
* http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/26039199#26039199
*/
function isElementPartiallyInViewport(el)
{
//special bonus for those using jQuery
if (typeof jQuery !== 'undefined' && el instanceof jQuery) el = el[0];
var rect = el.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
@trentniemeyer
trentniemeyer / MixPanelExport.py
Last active March 6, 2024 14:53
MixPanel Export API in Python 3
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
#
# Copyright 2010-2013 Mixpanel, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@rbk
rbk / functions.php
Created June 8, 2016 19:55
Query WordPress and add the metadata to the result.
<?php
/*
*
* Get posts with a standard query
* Include all the meta data in the result
*
*/
function get_posts_with_meta( $args ) {
$query = get_posts($args);
@bradfrost
bradfrost / anatomy-of-a-successful-readme.md
Last active November 11, 2020 20:41
Anatomy of a successful README

Name of Project [version number] Build Status: Linux

]

[Introduction text about the project. This should be a short summary of the project that explains what it is and why anyone should care about it]

[optional image]

Getting Started

Requirements

[include a bulleted list of any dependencies your project requires. Include links to the dependencies, and additionally links to helpful resources to get up and running with the project's dependencies]

@charleskorn
charleskorn / superagent.js
Last active September 6, 2021 06:40 — forked from pherris/superagent.js
A Jest mock for superagent. Place in your __mocks__ directory.
'use strict';
var mockDelay;
var mockError;
var mockResponse = {
status: function () {
return 200;
},
ok: true,
get: jest.genMockFunction(),
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active April 13, 2024 16:19
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest