Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@aleclarson
aleclarson / OuterBorder.coffee
Created November 14, 2016 19:41
OuterBorder (for React Native)
{Component, Device} = require "modx"
hexToRgb = require "hex-rgb"
type = Component "OuterBorder"
type.defineProps
style: Style
child: Element
@aleclarson
aleclarson / utils.coffee
Created April 18, 2017 20:33
React debug utils
global.getParentView = do ->
ReactInstanceMap = require "ReactInstanceMap"
return (view, level = 1) ->
unless view._reactInternalInstance
view = view._currentElement._owner._instance
parent = ReactInstanceMap.get view
while parent and --level >= 0
@aleclarson
aleclarson / docker.md
Last active September 16, 2017 02:39
Docker tips & tricks

Explore filesystem of a container

docker exec -t -i b5ae54373681 /bin/bash

Copy container to host directory

docker cp b5ae54373681:app ~/app-b5ae54373681

Copy host directory to localhost

scp -r [email protected]:/home/vagrant/app-b5ae54373681 ~/app-b5ae54373681

Inspect container that failed to build

@aleclarson
aleclarson / script.sh
Last active September 2, 2017 15:36
Read a .gitignore-like file with Bash
#!/bin/bash
read_lines() {
while IFS='' read -r line || [[ -n $line ]]; do
if [ -z "${line// }" ] || [[ $line == "#"* ]]; then continue; fi
echo "$line"
done < "$1"
}
if [ -f "$1" ]; then read_lines "$@"; fi
@aleclarson
aleclarson / dokku-redeploy-fix.conf
Last active September 20, 2017 17:27
Dokku redeploy fix
description "Dokku app redeploy fix service"
start on started dokku-reploy
exec start-stop-daemon --start -c dokku --exec /usr/bin/dokku-redeploy-fix
@aleclarson
aleclarson / README.md
Last active September 21, 2020 03:13
node-gyp build.js

Build the native binding of a NodeJS library for multiple platforms/versions.

With no arguments, this script use the nearest node-gyp installation to build binding.gyp for the version of node being used. Then it looks for binding.node in the resulting build/Release directory, and copies it into the vendor directory (created on-the-fly). You will find it inside a subdirectory named ${process.platform}-${process.arch}-${moduleVersion}.

When --target or --version are undefined, this script resolves their values for you.

NOTE: You must specify --version if you specify --target as a version not currently used by your shell.

After building the native binding, you can npm rm bindings and use the provided binding.js module for loading your native binding with require. The binding.js module is smart enough to know which vendor subdirectory contains the appropriate binding for the current process.

@aleclarson
aleclarson / css-rules.js
Created October 26, 2017 22:52
Javascript-driven CSS rules
const capsRE = /([A-Z])/g;
const $styles = $('<style>').appendTo(document.head);
exports.addRule = function(selector, style) {
$styles.append(formatRule(selector, style));
};
function formatRule(selector, style) {
@aleclarson
aleclarson / README.md
Created November 14, 2017 01:33
Call a listener once the given stylesheets have loaded
const styles = require('./styles')
const promise = styles.onLoad('foo.css', 'bar.css')

promise.then(() => {
  console.log('Stylesheets loaded!')
  // Now, measurements can be done safely!
})
@aleclarson
aleclarson / styles.less
Created November 15, 2017 16:54
Atom stylesheet customizations
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/
@aleclarson
aleclarson / defer.js
Created December 1, 2017 19:01
Promise.defer + flow
// @flow
export type Deferred<T> = {
promise: Promise<T>,
resolve: (value: T) => void,
reject: (error: Error) => void,
}
export function defer(): Deferred<any> {
const deferred = {}