Skip to content

Instantly share code, notes, and snippets.

View redbar0n's full-sized avatar

redbar0n

View GitHub Profile
@redbar0n
redbar0n / gist:abb2524c9a883b11b44a
Created March 6, 2015 08:29
capybara-webkit fails after trying to find an element around 70 times..
it "the state 'Completed' should be tracked correctly", :js => true do
visit show_video_path(:unit_id => @unit.id, :channel_id => Channel.first.id, :w => 600, :h => 450)
puts "--- trying to click video ---"
#page.find("div.vjs-big-play-button").click #click play video button
find(:xpath,'//div[contains(@class,"vjs-big-play-button")]').click #click play video button -- alternative find method
# some more code, not being reached during execution...
puts "---"
end
@redbar0n
redbar0n / gist:1a2a201418e626357dfa
Last active August 29, 2015 14:16
capybara-webkit doesn't catch .onEnded events from videojs, causing a lacking "VIDEOJS END OF VIDEO" output here
---
My system specs:
---
OSX Mavericks 10.9.5
capybara 2.4.4
capybara-webkit 1.4.1
---
Videojs code from [video.js](https://github.com/videojs/video.js):
---
@redbar0n
redbar0n / gist:8fdc90cbc918d286725e
Last active January 28, 2016 13:03
capybara-webkit evaluate_script vs execute_script
Regarding this article: http://makandracards.com/makandra/12317-capybara-selenium-evaluate_script-might-freeze-your-browser-use-execute_script
code:
puts page.evaluate_script("2+3;").to_i
output:
Started "Evaluate(2+3;)"
Finished "Evaluate(2+3;)" with response "Success(5)"
Wrote response true "5"
@redbar0n
redbar0n / gist:82d253e319c7e120bcdb
Created July 23, 2015 21:46
capybara-webkit 1.5.2 still doesn't catch .onEnded events from videojs, so any video playing will not end (and tests will stall indefinitely)
---
My system specs:
---
OSX Mavericks 10.9.5
capybara 2.4.4
capybara-webkit 1.5.2
---
Videojs code from [video.js](https://github.com/videojs/video.js):
# Couldn't update the tiny_tds version installed with yum, since the yum repo didn't have the latest tiny_tds version.
# So remove tiny_tds installed by yum, to avoid conflicts with the succeeding binary tarball install.
# Note: yum installs freetds.conf into /etc/freetds.conf
# Answer y to remove dependent libraries.
printf 'y' | sudo yum remove freetds
# Download FreeTDS latest stable version (as of Jan 4, 2018) from binary tarball.
cd /tmp
wget http://www.freetds.org/files/stable/freetds-1.00.80.tar.gz
tar -xzf freetds-1.00.80.tar.gz
@redbar0n
redbar0n / conditional_formatting.gs
Last active July 26, 2020 04:11
Google Sheets - How to format cells through code in Google Sheets. Option 3: Setting a conditional formatting rule through your script.
function yourScript() {
// ...
var cellsInA1Notation = "A1"; // could also have been e.g. "C3:D4"
setRangeToRedBackground(cellsInA1Notation);
// ...
}
// This is a custom convenience function I made which is not provided directly by the Google Sheets API.
function addConditionalFormatRule(sheet, rule) {
var rules = sheet.getConditionalFormatRules();
@redbar0n
redbar0n / conditional_formatting_with_criteria.gs
Last active July 26, 2020 04:12
Google Sheets - How to format cells through code in Google Sheets - Option 3: Using `SpreadsheetApp.newConditionalFormatRule().withCriteria` instead of using `.whenFormulaSatisfied()`
// Alternatively: Using withCriteria. Requires more boilerplate than using whenFormulaSatisfied.
// This code shows the same case above as a specific instance of the general case of using withCriteria,
// which has a bit more boilerplate setup.
function setRangeToRedBackground(cellsInA1Notation) {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(cellsInA1Notation);
var customFormulaString = "=A1=1";
var criteria = SpreadsheetApp.BooleanCriteria.CUSTOM_FORMULA; // booleanConditionCriteriaType is an alternative name for this
var argsArray = [customFormulaString]; // booleanConditionCriteriaValues is an alternative name for this
// Could have used the convenience method whenFormulaSatisfied instead of withCriteria (withCriteria is probably what it uses internally).
@redbar0n
redbar0n / set_color_on_open.gs
Last active April 30, 2020 17:26
Google Sheets - How to format cells through code in Google Sheets. Option 1: Automatically when the spreadsheet opens.
// This does not set the color of a user-selected cell like using getActiveCell does,
// but it necessarily relies on getActiveSheet(), since ranges are defined as referencing cells within sheets.
function setBackgroundOfScriptDeclaredCell() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1");
range.setBackground("red");
}
// Will run when user opens/refreshes spreadsheet.
function onOpen() {
@redbar0n
redbar0n / set_color_when_user_clicks_menu.gs
Last active April 30, 2020 14:37
Google Sheets - How to format cells through code in Google Sheets. Option 2: When user initiates your script
// Add custom menu to spreadsheet
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Run custom script')
.addItem('Set background of a script-declared cell (A1)', 'setBackgroundOfScriptDeclaredCell')
.addToUi();
}
// This does not set the color of a user-selected cell like using getActiveCell does, but it necessarily relies on getActiveSheet(), since ranges are defined as referencing cells within sheets.
function setBackgroundOfScriptDeclaredCell() {
@redbar0n
redbar0n / form_of_data_construct.md
Last active December 18, 2020 13:59
Is there any IDE that allows you to augment your code with the form of your data in real time?

Here's a crazy idea. Take the following simple example (in javascript):

    var m = [[1], [2], [3]];
    // ... a lot of code in between, perhaps m was passed through
    // several functions without TypeScript type declarations, so you might mistakenly
    // think m is a simple array like [1, 2, 3] at this point...
    var m2 = [];
    m.forEach(x => {
 m2.push(x); //# [[number], [number], ...] will be the form of m2 here