Skip to content

Instantly share code, notes, and snippets.

@ariofrio
ariofrio / active_gpu.1m.py
Last active June 6, 2020 05:58
Improved version of Bitbar Active GPU Plugin with support for changing GPU switching mode (like gfxCardStatus, but it works on macOS Mojave). Original: https://getbitbar.com/plugins/System/active_gpu.1m.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Active GPU</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Eric Ripa</bitbar.author>
# <bitbar.author.github>eripa</bitbar.author.github>
# <bitbar.desc>Displays an image based on the active GPU in multi-GPU machines, such as the MacBook Pro</bitbar.desc>
# <bitbar.image>http://i.imgur.com/v2MuPOi.png</bitbar.image>
# <bitbar.dependencies></bitbar.dependencies>
# <bitbar.abouturl></bitbar.abouturl>
export function mapValues<A, B>(
obj: { [key: string]: A },
f: (x: A) => B
): { [key: string]: B } {
const rv: { [key: string]: B } = {}
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
rv[key] = f(obj[key])
}
@ariofrio
ariofrio / main.jsx
Created July 6, 2015 23:40
Using Director.js with React.js (uses ES6 extensions)
import router from './router.jsx';
import A from './A.jsx';
import B from './B.jsx';
import C from './C.jsx';
router.on('/a', () => { React.render(<A />, document.body); });
router.on('/b', () => { React.render(<B />, document.body); });
router.on('/c', () => { React.render(<C />, document.body); });
router.init();
@ariofrio
ariofrio / colors-utils.js
Created May 6, 2014 22:35
RGB parsing functions in Javascript
// http://stackoverflow.com/a/5624139/237285
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? [
parseInt(result[1], 16),
parseInt(result[2], 16),
@ariofrio
ariofrio / gist:8295235
Created January 7, 2014 06:05
Get the first two words of the names of all people in a Facebook Graph Search
var els = document.querySelectorAll("#browse_result_area [data-bt='{\"ct\":\"title\"}'] a");
var ret = ""
for(var i=0; i<els.length; i++) {
ret += /\w+ \w+/.exec(els[i].textContent) + ",";
}
@ariofrio
ariofrio / install-wp-nfshost.sh
Created May 18, 2013 09:16
Script that installs Wordpress on NearlyFreeSpeech.net. Takes care of safe_mode permissions, temporary folder, and automatic installation of plugins, etc.
#!/bin/sh
set -ex
cd /home/public
# Download Wordpress
wget http://wordpress.org/latest.tar.gz
tar -xf latest.tar.gz
rm latest.tar.gz
mv wordpress/* .
rmdir wordpress
*.io.run
@ariofrio
ariofrio / debug.cpp
Created December 2, 2012 02:13
C++ output stream proxy that adds a prefix to every line
#include "debug.h"
debug_stream debug;
@ariofrio
ariofrio / post-receive
Created July 25, 2012 21:48
Post-receive script for Goatee deployment, inspired by Heroku
#!/bin/bash
# Fail fast.
set -e
# Debug.
# set -x
function indent() {
c='s/^/ /'
This file has been truncated, but you can view the full file.