Skip to content

Instantly share code, notes, and snippets.

View AndrewJHart's full-sized avatar
:atom:
Building react apps & micro-services

Andrew Hart AndrewJHart

:atom:
Building react apps & micro-services
View GitHub Profile
@markerikson
markerikson / react-controlled-inputs.md
Last active June 15, 2021 12:50
React "controlled" vs "uncontrolled" inputs explanation

[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

@cwisecarver
cwisecarver / base.py
Created May 27, 2016 00:07
Working server_side_cursors in django 1.9
import uuid
import psycopg2
from django.conf import settings
from django.db.backends import utils
from django.db.backends.postgresql.base import \
DatabaseWrapper as PostgresqlDatabaseWrapper
from django.db.backends.postgresql.base import *
@mahmoud
mahmoud / remerge.py
Last active November 29, 2023 09:08
Recursively merging dictionaries with boltons.iterutils.remap. Useful for @hynek's configs. https://twitter.com/hynek/status/696720593002041345
"""
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.
"""
@sasxa
sasxa / emitter.service.ts
Created January 2, 2016 05:27
Angular2 Communicating between sibling components
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];
#!/usr/bin/php
<?php
function closure_test(&$foobar) {
// Repeat for some arbitrary number of executions
$x = mt_rand(3, 10);
while ($x > 0) {
$foobar[] = $x;
--$x;
from collections import OrderedDict
from rest_framework import serializers
class SkipField(Exception):
pass
class ExtensibleModelSerializer(serializers.ModelSerializer):
'''
@lukehorvat
lukehorvat / es6-map-to-object-literal.js
Last active January 8, 2024 10:32
Convert ES6 Map to Object Literal
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }
@AndrewJHart
AndrewJHart / Backbone.AnimView.js
Created February 22, 2015 19:58
Rough demonstration of creating transitionIn and transitionOut declarative properties on any of your backbone views to provide CSS powered animations into your view. Note this copy was used to extend the framework Thorax, but will little work should be easily made to work w/ backbone by itself. To make this work you will also need to create a Ro…
// Definition would look like to create a detail view
/*
var DetailView = AnimView.extend({
name: "detail",
template: template,
// classes for this view
className: 'detail',
// animation properties
@carlbennett
carlbennett / lunch.sh
Last active July 10, 2017 16:28
Lunch Location Randomizer
#!/bin/bash
TODAY=$(date +%Y-%m-%d)
LIST=$(sed -e 's/$/\r/g' lunch.txt | perl -MURI::Escape -ne 'print uri_escape($_)')
curl -s \
-d "list=${LIST}" \
-d "format=plain" \
-d "rnd=date.${TODAY}" \
"https://www.random.org/lists/?mode=advanced"
@mculp
mculp / voices.txt
Created December 3, 2014 00:14
List of voices available by the `say` command on OS X
Agnes en_US # Isn't it nice to have a computer that will talk to you?
Albert en_US # I have a frog in my throat. No, I mean a real frog!
Alex en_US # Most people recognize me by my voice.
Alice it_IT # Salve, mi chiamo Alice e sono una voce italiana.
Alva sv_SE # Hej, jag heter Alva. Jag är en svensk röst.
Amelie fr_CA # Bonjour, je m’appelle Amelie. Je suis une voix canadienne.
Anna de_DE # Hallo, ich heiße Anna und ich bin eine deutsche Stimme.
Bad News en_US # The light you see at the end of the tunnel is the headlamp of a fast approaching train.
Bahh en_US # Do not pull the wool over my eyes.
Bells en_US # Time flies when you are having fun.