Skip to content

Instantly share code, notes, and snippets.

View ianobermiller's full-sized avatar

Ian Obermiller ianobermiller

View GitHub Profile
@ianobermiller
ianobermiller / gist:5381688
Created April 14, 2013 06:32
Histogram image in C#
public static class Histogram
{
public static SortedDictionary<int, int> ToHistogram(this IEnumerable<int> nums)
{
var dict = new SortedDictionary<int, int>();
foreach (var n in nums)
{
if (!dict.ContainsKey(n))
dict[n] = 1;
else
@ianobermiller
ianobermiller / index.html
Created July 12, 2021 00:47
WiFi QR Code, single HTML file
<!DOCTYPE html>
<html>
<head>
<title>WiFi Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- https://news.ycombinator.com/item?id=26923316 -->
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>&#128272;</text></svg>">
<style>
body, textarea {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// Create a ref that we add to the element for which we want to detect outside clicks
const ref = useRef();
// State for our modal
const [isModalOpen, setModalOpen] = useState(false);
const openModal = useCallback(() => setModalOpen(true), []);
const closeModal = useCallback(() => setModalOpen(false), []);
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// Ref for the element that we want to detect whether on screen
const ref = useRef();
// Call the hook passing in ref and root margin
// In this case it would only be considered onScreen if more ...
// ... than 300px of element is visible.
const onScreen = useOnScreen(ref, '-300px');
@ianobermiller
ianobermiller / radium-issue-462.jsx
Last active January 4, 2016 19:11 — forked from YonasBerhe/gist:ce2fea747650ee7d9d5c
Hoisting issue using radium
import Radium from 'radium';
import React from 'react';
import ReactDOM from 'react-dom';
// import Radium, { Style } from 'radium';
var FakeUser = React.createClass({
getInitialState: function() {
return {firstname: '', lastName: '', gender: '', location: '', email: '', username: '', password: '', picture: ''};
@ianobermiller
ianobermiller / example.js
Last active December 27, 2015 03:39
Saw this post on HN about optimizing AngularJS (http://blog.scalyr.com/2013/10/31/angularjs-1200ms-to-35ms/) and I wondered how React would fare. Turns out it can be pretty fast. I did have to use a similar trick of breaking up the line only when the mouse is over it, but no messing with custom directives needed. You can try it yourself by dropp…
/**
* @jsx React.DOM
*/
var text1 = document.getElementById('text1').textContent;
var text2 = document.getElementById('text2').textContent;
var LinksDemo = React.createClass({
getInitialState: function() {
return {text: text1};
@ianobermiller
ianobermiller / gist:5360760
Last active December 16, 2015 02:09
Unicode Character Names in JSON via http://www.unicode.org/charts/charindex.html
{
"00C1": "A WITH ACUTE, LATIN CAPITAL LETTER",
"00E1": "A WITH ACUTE, LATIN SMALL LETTER",
"0103": "A WITH BREVE, LATIN SMALL LETTER",
"01CE": "A WITH CARON, LATIN SMALL LETTER",
"00C2": "A WITH CIRCUMFLEX, LATIN CAPITAL LETTER",
"00E2": "A WITH CIRCUMFLEX, LATIN SMALL LETTER",
"00C4": "A WITH DIAERESIS, LATIN CAPITAL LETTER",
"00E4": "A WITH DIAERESIS, LATIN SMALL LETTER",
"0227": "A WITH DOT ABOVE, LATIN SMALL LETTER",