Skip to content

Instantly share code, notes, and snippets.

View slmyers's full-sized avatar
💯
crushing code

Steven Myers slmyers

💯
crushing code
View GitHub Profile
@slmyers
slmyers / gist:fc3ae96093719c2f66779f0574cc6555
Created February 23, 2020 01:32 — forked from andlima/gist:1774060
Median of medians selection algorithm
int find_kth(int *v, int n, int k) {
if (n == 1 && k == 0) return v[0];
int m = (n + 4)/5;
int *medians = new int[m];
for (int i=0; i<m; i++) {
if (5*i + 4 < n) {
int *w = v + 5*i;
for (int j0=0; j0<3; j0++) {
int jmin = j0;
@slmyers
slmyers / README.md
Created January 30, 2020 15:33 — forked from nikcub/README.md
Facebook PHP Source Code from August 2007
@slmyers
slmyers / DateRangePicker.jsx
Created January 22, 2020 16:47 — forked from Skitionek/DateRangePicker.jsx
Range select for @mui-org/material-ui-pickers
import React, { useContext, useRef, useState } from 'react'
import { DatePicker, MuiPickersContext } from '@material-ui/pickers'
import withStyles from '@material-ui/core/styles/withStyles'
import clsx from "clsx";
import { useStyles as dayStyles } from '@material-ui/pickers/views/Calendar/Day';
function DateRangePicker({
classes,
value,
onChange,
@slmyers
slmyers / coverage.js
Created February 26, 2018 22:55 — forked from ebidel/coverage.js
CSS/JS code coverage during lifecycle of page load
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*
* Shows how to use Puppeeteer's code coverage API to measure CSS/JS coverage across
* different points of time during loading. Great for determining if a lazy loading strategy
* is paying off or working correctly.
*
* Install:
* npm i puppeteer chalk cli-table
@slmyers
slmyers / lumen.lua
Created March 18, 2017 19:27 — forked from anonymous/lumen.lua
Self-hosted Lisp using vvander's Lua browser runtime: https://cdn.rawgit.com/vvanders/wasm_lua/d68f46a8/main.html
environment = {{}}
target = "lua"
function nil63(x)
return(x == nil)
end
function is63(x)
return(not nil63(x))
end
function no(x)
return(nil63(x) or x == false)
interface Position {
left:string;
top: string;
}
@Component({
selector: 'drag-demo',
template: `
<div #target [ngStyle]="boxPosition | async">drag me</div>
`
})
@slmyers
slmyers / mutex.js
Last active June 2, 2016 18:36 — forked from artursapek/mutex.js
// Originally taken from https://github.com/mgtitimoli/await-mutex
class Mutex {
constructor() {
this._locking = Promise.resolve();
this._locked = false;
}
isLocked() {
return this._locked;
const cache = {}
export default getJSONWithCache(url) {
return cache[url] ?
Promise.resolve(cache[url]) :
getJSON(url).then(json => {
cache[url] = json
return json
})
}

Difference between Debounce and Throttle

Debounce

Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.

Throttle

@slmyers
slmyers / active-record-migration-expert.md
Created February 18, 2016 19:03 — forked from pyk/active-record-migration-expert.md
become active record migration expert (Rails 4.0.2)

become active record migration expert (Rails 4.0.2)

workflow:

create model

$ rails g model NameOfModel
    invoke  active_record
    create    db/migrate/YYYYMMDDHHMMSS_create_name_of_models.rb