Skip to content

Instantly share code, notes, and snippets.

/*!
* jQuery JavaScript Library v3.7.0
* https://jquery.com/
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2023-05-11T18:29Z
*/
@btwelch
btwelch / gist:0e14e3326ef8e8767cae38a6b8e9dea5
Created December 29, 2023 16:52
Simple client interface for javascript, using fetch
export class Client {
Success = 'Success';
Error = 'Error';
async getData(path) {
let fullPath = path;
const result = await fetch(fullPath, {
method: 'GET',
headers: {
Accept: 'application/json',
@btwelch
btwelch / gist:49d0d8f8dde38fb06c66e980276b0585
Created December 28, 2023 16:09
Active Admin Addons: providing names with context
# /app/admin/api_key.rb
ActiveAdmin.register ApiKey do
include UserFilter
controller do
def permitted_params
params.permit!
end
end
end
module TrackedRetries
def with_tracked_retries(sync_record, max_attempts: 3)
attempts = 0
begin
attempts += 1
sync_record.update(attempts: attempts)
yield
sync_record.update(success: true)
application_controller.rb
...
private
def authenticate_user!
super
check_user_active!
end
@btwelch
btwelch / gist:d695e56457734e3c3b5de2eed73695a0
Created April 29, 2021 22:31
Hall Effect Tachometer - Rasberry Pi
import time, datetime, sys
import RPi.GPIO as GPIO
sense_pin = 7
LED_pin = 36
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sense_pin, GPIO.IN)
GPIO.setmode(LED_pin, GPIO.OUT)
last_time = time.time()
<html>
<head>
<style type='text/css'>
body, html {
margin: 0;
padding: 0;
}
body {
color: black;
display: table;
@btwelch
btwelch / Component.jsx
Created June 26, 2018 16:27 — forked from krambertech/Component.jsx
ReactJS: Input fire onChange when user stopped typing (or pressed Enter key)
import React, { Component } from 'react';
import TextField from 'components/base/TextField';
const WAIT_INTERVAL = 1000;
const ENTER_KEY = 13;
export default class TextSearch extends Component {
constructor(props) {
super();
@btwelch
btwelch / gist:49110630d4c5fadbfdde
Created January 24, 2015 17:49
Rails Pagination Example
# This is how it is done, even in Rails 4
gem 'will_paginate'
@stripe_events = StripeEvent.paginate(:page => params[:page], :per_page => 20)
<% will_paginate @stripe_events %>
@btwelch
btwelch / gist:422aac4dce4b9ae46323
Created January 24, 2015 16:20
Gem install specific version
gem install GEM_NAME -v SPECIFIC_VERSION
e: gem install autoprefixer-rails -v 5.0.0.1