Skip to content

Instantly share code, notes, and snippets.

View adamduren's full-sized avatar

Adam Duren adamduren

View GitHub Profile
@adamduren
adamduren / program.js
Last active October 20, 2022 15:27
Elevator Saga
{
init: function(elevators, floors) {
const DIR_UP = 'up';
const DIR_DOWN = 'down';
const pendingPickupDirectionDownFloors = new Set();
const pendingPickupDirectionUpFloors = new Set();
const buttonPressedHandlerFactory = (floor, direction) => () => {
console.log(`Button pressed on floor ${floor.floorNum()} going ${direction}`);
@adamduren
adamduren / stripe-token.ts
Created June 11, 2019 12:18
Create Token from JS with `cordova-plugin-applepay`
// Reverse Engineered from
// https://github.com/stripe/stripe-ios/blob/d4e3170fab9ab940816ea28ea8084b48a842e764/Stripe/STPAPIClient%2BApplePay.m#L22-L28
class StripeToken {
// IPaymentResponse is the response from `makePayment()`
public async getTokenFromPaymentData(payment: IPaymentResponse) {
const payload: any = {
pk_token: atob(payment.paymentData),
...this.addressParamsFromPaymentData(payment),
};
@adamduren
adamduren / my-page.component.html
Created February 22, 2019 20:19
Workaround for relative urls with ion-back-button[defaultHref]
<ion-back-button [defaultHref]="relativeUrl('..')"></ion-back-button>
@adamduren
adamduren / index.js
Created November 20, 2017 17:49
FullCalendar Sticky First Column & Header
this.$el = $(this.element.nativeElement);
const scrollableBody = this.element.querySelector('.fc-content-skeleton');
const scrollableHeader = this.element.querySelector('.fc-head-container > .fc-row');
const scrollableBg = this.element.querySelector('.fc-bg');
scrollableBody.addEventListener('scroll', () => {
scrollableHeader.scrollTo(scrollableBody.scrollLeft, 0);
scrollableBg.scrollTo(scrollableBody.scrollLeft, 0);
});
@adamduren
adamduren / react-select.d.ts
Created September 21, 2016 21:11
Add AsyncCreatable to typings
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/86b7c1a2688e38d8db2f53bf9949e7caec0d7630/react-select/react-select.d.ts
declare namespace ReactSelect {
interface AutocompleteResult {
/** the search-results to be displayed */
data: Option[],
/** Should be set to true, if and only if a longer query with the same prefix
* would return a subset of the results
* If set to true, more specific queries will not be sent to the server.
@adamduren
adamduren / remoteConfig.js
Created September 10, 2015 02:05
Remote logger in angularJs using console.re
.config(['$provide', ($provide) => {
$provide.decorator('$log', ($delegate) => {
let wrapper = {};
Object.keys($delegate).forEach((key) => {
let delegateFn = $delegate[key];
let remoteFn = console.re[key];
wrapper[key] = () => {
delegateFn.apply(delegateFn, arguments);
remoteFn.apply(remoteFn, arguments);
};
@adamduren
adamduren / test_wait.py
Last active August 29, 2015 14:14
Thoughts on Selenium Explicit VS Implicit Waits
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
class BaseTestClass(object):
def __init__(self, driver):
self.wait = WebDriverWait(driver, 5, .25, (NoSuchElementException,))
@adamduren
adamduren / gist:afe6ad54473f006b86a9
Last active August 29, 2015 14:08
EnsureCsrfCookieMixin
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie
class EnsureCsrfCookieMixin(object):
@method_decorator(ensure_csrf_cookie)
def dispatch(self, *args, **kwargs):
return super(EnsureCsrfCookieMixin, self).dispatch(*args, **kwargs)
@adamduren
adamduren / gist:ca45d1fe5eb891eb226c
Created October 28, 2014 21:34
Sublime Settings
{
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"ensure_newline_at_eof_on_save": true,
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"indent_to_bracket": true,
"shift_tab_unindent": true,
@adamduren
adamduren / better_diff_stats.py
Last active August 29, 2015 14:03
Give you a github style diffstats, with the ability to exclude paths for more relevancy.
from __future__ import print_function
import sys
# Gives you a github style diffstats.
# With the ability to exclude paths for more relevancy.
#
# Generate a diffstat file with:
# git diff --numstat master...HEAD > stats.diff
#