Skip to content

Instantly share code, notes, and snippets.

@DanielHeath
DanielHeath / slim2erb.rb
Created January 30, 2024 03:05
Had enough of Slim in your rails app? Slim2ERB does a reasonable job of auto-converting any files that don't generate eyebleeding source.
require 'slim/erb_converter'
def reject_newlines_in(content)
result = []
content.each do |item|
next if item == [:newline]
if item.is_a? Array
result.push(reject_newlines_in(item))
else
@DanielHeath
DanielHeath / system.report
Created July 31, 2019 00:59
SteamVR system report
This file has been truncated, but you can view the full file.
SteamVR System Report created Wed Jul 31 10:58:45 2019
<Report>
SteamVR Version: 1.6.10 (1564442420)
SteamVR Date: 2019-07-30
Steam: Public
Steam Branch: beta
Steam AppID: 250820
Tracking: lighthouse
OS: Linux version 4.18.0-25-generic (buildd@lcy01-amd64-025) (gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.10.1)) #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019
@DanielHeath
DanielHeath / csv_import.rb
Created September 4, 2018 23:52
How I do CSV imports with postgres & rails
class CsvImport
include ActiveRecord::Sanitization::ClassMethods
attr_accessor :connection, :header
def self.read_csv(file)
file.is_a?(Array) ? file : file.read.encode(newline: :universal).lines
end
def initialize(connection, csv_lines, table_name)
@connection, @table_name = connection, table_name
@DanielHeath
DanielHeath / chrome_tracing.rb
Last active July 18, 2018 07:05
Javascript coverage with selenium & chrome. Must not compile an asset bundle (or otherwise transpile assets) in test mode.
# TODO: Support headless-chrome (does not have chrome://version page)
# Probably needs 'sys/proctable' or similar as it's not exposed otherwise.
module ChromeTracing
def self.register_simplecov!
require 'simplecov'
SimpleCov.profiles.define "jscov" do
# ignore RB but not JS in vendor
filters.clear
//= require jquery
//= require lodash
$(function() {
var input = $('#searchInput'),
loader = $('#loader'),
searchInputTarget = $('#searchTarget'),
value = input.val();
if (!input.length)
@DanielHeath
DanielHeath / nvm.sh
Created January 10, 2017 23:16
How I source nvm (because it's slow
#!/usr/bin/env bash
export NVM_DIR="$HOME/.nvm"
function _source_nvm() {
if [ -z "$NVM_PATH" ] ; then
# Prevent infinite recursion
unset -f nvm;
unset -f npm;
unset -f grunt;
. /usr/local/opt/nvm/nvm.sh;

How does npm >4.0 work with shrinkwrapping?

What happens when I run npm i without a shrinkwrap file

For each dependency specified in package.json, npm attempts to find a compatible version, and installs it (and all dependencies, transitively) to node_modules

What happens when I run npm i with a shrinkwrap file

The exact versions of the libraries specified in the shrinkwrap file are installed, regardless of whether they match package.json or have their dependencies met.

What happens when I run npm shrinkwrap?

The exact versions of the currently installed libraries in node_modules are written to npm-shrinkwrap.json.

@DanielHeath
DanielHeath / deploy.sh
Last active August 1, 2016 03:38
Deploying to github pages, from e.g. a webpack static site generator [OSX/LINUX]
#!/usr/bin/env bash
set -o pipefail # If you pipe one command into another, fail the whole lot if any fail
set -e # fail if there are any errors in the script
set -u # fail if you use an uninitialized variable
# Warn about the dire consequences of this action
read -r -p "THIS WILL WIPE OUT ANY UNCOMMITTED CHANGES - control-c to stop" yn
HEAD=$(git rev-parse HEAD) # Save where you're up to
git reset --hard "$HEAD" # Avoid using uncommitted changes to build the site
@DanielHeath
DanielHeath / .env
Last active December 14, 2016 05:05
Setting up a go project to produce a binary
export GOPATH="$(pwd):$(pwd)/vendor"
export PATH="$(pwd)/bin:$PATH"
export CDPATH=.:$(pwd)/src/github.com:$(pwd)/vendor/src/golang.org:$(pwd)/src
if [ -f .env.secret ] ; then
source .env.secret
fi
@DanielHeath
DanielHeath / Last output lines
Last active May 3, 2016 04:38
Flowtype hardlock (0.24.0, installed via flow-bin on linux, run under gnu parallel in a docker container running debian jessie)
flow is still initializing; this can take some time. [local inference] \flow is still initializing; this can take some time. [local inference] |flow is still initializing; this can take some time. [local inference] /flow is still initializing; this can take some time. [local inference] -flow is still initializing; this can take some time. [local inference] \flow is still initializing; this can take some time. [local inference] |flow is still initializing; this can take some time. [local inference] /flow is still initializing; this can take some time. [local inference] -flow is still initializing; this can take some time. [local inference]
It just sits printing these at 100% CPU for hours