Skip to content

Instantly share code, notes, and snippets.

View Dkendal's full-sized avatar

Dylan C. Kendal Dkendal

View GitHub Profile
# find a cell based on the _exact_ text in the column, and a row that
# _contains_ the row text.
def within_cell column, row
col_eq = "text()='#{column}'"
col_index = "count(//table//td[#{col_eq}]/preceding-sibling::*) + 1"
row_matches = "..//td/text()[contains(., '#{row}')]"
within(:xpath, "//table//td[#{col_index}][#{row_matches}]") { yield }
end
@paulirish
paulirish / what-forces-layout.md
Last active June 19, 2024 15:52
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@fmoralesc
fmoralesc / italics.vim
Last active January 10, 2018 20:21
vim + italics
" cd to the folder where you have xterm-256color.terminfo, run
" $ tic xterm-256color.terminfo
" and add the following to your vimrc.
set t_ZH=
set t_ZR=
@evancz
evancz / Ports.js
Last active March 21, 2019 17:37
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
@emmaly
emmaly / gist:8267078
Created January 5, 2014 11:21
Bash script to automatically switch PulseAudio sink to Bluetooth headset on connect with A2DP profile and 50% volume.
#!/bin/bash
sink_name="bluez_sink.00_42_1B_AD_FA_CE"
if [ -z "$1" ]; then
dbus-monitor --system "path=/org/bluez/777/hci0/dev_00_42_1B_AD_FA_CE, interface=org.bluez.AudioSink, member=Connected" | while read line; do
echo $line
$0 1
done
else
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 20, 2024 14:04
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@steve9001
steve9001 / application.rb
Created December 7, 2011 16:18
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@eriksoe
eriksoe / erlang-java-interop-demo.sh
Created August 15, 2011 20:58
An Erlang-Java Interop Demo - executable summary
#!/bin/bash -x
#######################################################################
#
# Demo of Erlang IDL, as applied to property testing of Java code.
# We'll need Triq.
git clone git://github.com/krestenkrab/triq.git
(cd triq && ./rebar compile)
ERL_ROOT=`erl -noshell -eval 'io:format("~s\n", [code:root_dir()]), init:stop().'`
@jweir
jweir / protovis_to_link.js
Created November 19, 2010 19:23
How to save SVG data to a file from a web browser
/* ----------------------------------------------------------------------------------------------------
Super Form Reset
A couple of things to watch out for:
- IE8: If a text input doesn't have padding on all sides or none the text won't be centered.
- The default border sizes on text inputs in all UAs seem to be slightly different. You're better off using custom borders.
- You NEED to set the font-size and family on all form elements
- Search inputs need to have their appearance reset and the box-sizing set to content-box to match other UAs