Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Andrew Hart AndrewJHart

🏠
Working from home
Block or report user

Report or block AndrewJHart

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AndrewJHart
AndrewJHart / vanilla-ajax-poll.js
Created Sep 4, 2019 — forked from twmbx/vanilla-ajax-poll.js
Polling in JS with an async ajax call that returns a promise ( modified from: https://davidwalsh.name/javascript-polling )
View vanilla-ajax-poll.js
// The polling function
function poll(fn, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
var checkCondition = function(resolve, reject) {
var ajax = fn();
// dive into the ajax promise
ajax.then( function(response){
// If the condition is met, we're done!
@AndrewJHart
AndrewJHart / react-controlled-inputs.md
Created Feb 19, 2018 — forked from markerikson/react-controlled-inputs.md
React "controlled" vs "uncontrolled" inputs explanation
View react-controlled-inputs.md

[12:03 AM] acemarke: "controlled" and "uncontrolled" inputs
[12:04 AM] acemarke: if I have a plain, normal HTML page, and I put <input id="myTextbox" type="text" /> in my page(edited)
[12:04 AM] acemarke: and I start typing into that textbox
[12:04 AM] acemarke: it remembers what I've typed. The browser stores the current value for that input
[12:05 AM] acemarke: and then sometime later, I can get the actual element, say, const input = document.getElementById("myTextbox"), and I can ask it for its value: const currentText = input.value;
[12:05 AM] acemarke: good so far?
[12:08 AM] acemarke: I'll keep going, and let me know if you have questions
[12:08 AM] lozio: ok, actually I'm reading
[12:09 AM] lozio: good
[12:09 AM] acemarke: so, a normal HTML input field effectively stores its own value at all times, and you can get the element and ask for its value

@AndrewJHart
AndrewJHart / restart_bluetooth.sh
Last active Nov 28, 2017 — forked from nicolasembleton/restart_bluetooth.sh
Restart Bluetooth Daemon on Mac OS X without restarting - this also works when the UI does not (preferences or menu bar)
View restart_bluetooth.sh
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@AndrewJHart
AndrewJHart / remerge.py
Created Oct 17, 2017 — forked from mahmoud/remerge.py
Recursively merging dictionaries with boltons.iterutils.remap. Useful for @hynek's configs. https://twitter.com/hynek/status/696720593002041345
View remerge.py
"""
This is an extension of the technique first detailed here:
http://sedimental.org/remap.html#add_common_keys
In short, it calls remap on each container, back to front, using the accumulating
previous values as the default for the current iteration.
"""
@AndrewJHart
AndrewJHart / webpack.config.js
Created May 8, 2017 — forked from JaySpears/webpack.config.js
Webpack 2.0 Configuration with React Example
View webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000/',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'app/index')
],
@AndrewJHart
AndrewJHart / emitter.service.ts
Created Feb 11, 2017 — forked from sasxa/emitter.service.ts
Angular2 Communicating between sibling components
View emitter.service.ts
import {Injectable, EventEmitter} from 'angular2/core';
@Injectable()
export class EmitterService {
private static _emitters: { [ID: string]: EventEmitter<any> } = {};
static get(ID: string): EventEmitter<any> {
if (!this._emitters[ID])
this._emitters[ID] = new EventEmitter();
return this._emitters[ID];
@AndrewJHart
AndrewJHart / jwt_authentication.py
Created Apr 13, 2016
JWT authentication middleware for django rest framework that populates the request.user object
View jwt_authentication.py
from django.utils.functional import SimpleLazyObject
from django.contrib.auth.models import AnonymousUser
from rest_framework.request import Request
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
def get_user_jwt(request):
"""
Replacement for django session auth get_user & auth.get_user for
@AndrewJHart
AndrewJHart / .env
Created Mar 18, 2016 — forked from allanlei/.env
Sample local Heroku/Django development environment using foreman
View .env
DATABASE_URL=postgres://USERNAME:PASSWORD@127.0.0.1/DATABASE
MEMCACHE_SERVERS=127.0.0.1:11211
DJANGO_SETTINGS_MODULE=settings.development.local
View mixins.py
class DynamicFieldsMixin(object):
"""
A serializer mixin that takes an additional `fields` argument that controls
which fields should be displayed.
Usage::
class MySerializer(serializers.HyperlinkedModelSerializer, DynamicFieldsMixin):
class Meta:
model = MyModel
@AndrewJHart
AndrewJHart / validate_uuid4.py
Created Feb 26, 2016 — forked from ShawnMilo/validate_uuid4.py
Validating a uuid4 with Python.
View validate_uuid4.py
from uuid import UUID
def validate_uuid4(uuid_string):
"""
Validate that a UUID string is in
fact a valid uuid4.
Happily, the uuid module does the actual
checking for us.
You can’t perform that action at this time.