Skip to content

Instantly share code, notes, and snippets.

@leosoto
leosoto / risky-copy.sh
Last active April 29, 2021 21:30
Get Risky Norris APV Share price and copy it to the macOS clipboard
YESTERDAY=$(date -v -1d +"%Y-%m-%d")
REAL_ASSET_ID=245 # Fintual Risky Norris Serie APV
API_URL=https://fintual.cl/api/real_assets/$REAL_ASSET_ID/days?date=$YESTERDAY
PRICE=$(curl $API_URL | jq ".data[0].attributes.price")
echo "Copying $PRICE to clipboard"
echo "$PRICE" | pbcopy
@leosoto
leosoto / airtable-example-post-to-external-api-integration.js
Last active November 16, 2020 20:46
airtable-example-post-to-external-api-integration.js
const control = base.getTable("Enqueue Scraping Control");
const controlResult = await control.selectRecordsAsync();
for (let controlRecord of controlResult.records) {
let name = controlRecord.getCellValueAsString("Name")
console.log("Enqueing " + name);
let table = base.getTable(controlRecord.getCellValue("table"));
let fieldPresentIfScraped = controlRecord.getCellValueAsString("fieldPresentIfScraped");
let lastEnqueueTime = Date.parse(controlRecord.getCellValue("lastEnqueueTime"));
let apiUrl = controlRecord.getCellValue("apiUrl");
let fieldWithUrlToEnqueue = controlRecord.getCellValueAsString("fieldWithUrlToEnqueue");
const table = await input.tableAsync("Pick a table");
const fields = [];
let moreFieldsAnswer;
do {
fields.push(await input.fieldAsync('Pick field to deduplicate', table));
moreFieldsAnswer = await input.buttonsAsync("Add more fields to deduplicate?", ['Add more fields', 'No']);
} while (moreFieldsAnswer == 'Add more fields');
const result = await table.selectRecordsAsync({
sorts: fields.map((f) => {return {field: f}})
@leosoto
leosoto / followers-mini-scraper.js
Last active February 22, 2021 13:59
Mini-scraper for linkedin followers
function scrapeData() {
let links = $$('.org-view-page-followers-modal__table-cell a')
let nameDivs = $$('.org-view-page-followers-modal__table-cell a .artdeco-entity-lockup__title')
let dateSpans = $$('.org-view-page-followers-modal__table-cell span span[aria-hidden]')
let captionDivs = $$('.org-view-page-followers-modal__table-cell a .artdeco-entity-lockup__caption')
let data = [];
for (let i = 0; i < links.length; i++) {
data.push([
nameDivs[i].innerText,
// Script for Google Spreadsheet
//
// Counts the number of cells inside countRange (string)
// which have the same color as the cell pointed out by
// colorRef (also as string). If a cell is merged then
// they are counted as mergeWeight cells instead of 1.
function COUNTCOLOR(countRange,colorRef,mergeWeight,_) {
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var range = activeSheet.getRange(countRange);
@leosoto
leosoto / feedback.md
Created October 2, 2018 22:52
Feedback a la guía de desarrollo de gobierno digital

Capítulo III

La sección 3 sobre escapar HTML sugiere un mecanismo frágil (escapar explícitamente) en lugar de uno sólido (separar por diseño safe strings de unsafe strings y obligar a que todo string se considere unsafe a menos que sea explícitamente marcado como safe, cosa que existe en frameworks modernos).

La sección 5.1 de contraseñas olvida mencionar que NUNCA se debe poner un máximo al largo de una contraseña.

La sección 6 de manejo de id sesión presume la existencia de "ids de sesión" que no son una necesidad (ej: signed cookies no requiere un id de sesión porque no hay una sesión en ninguna base de datos o servidor). También en la sección 6 falta considerar el tradeoff de que forzar muy seguido a los usuarios a loguearse puede hacer mas probable una fuga de la contraseña o que el usuario establezca una contraseña débil.

La sección 13 tiene una definición inventada de TDD (y sería raro recomendar a todo el mundo TDD pero entonces debieran cambiar el título de la sección para evitar confusión c

Keybase proof

I hereby claim:

  • I am leosoto on github.
  • I am leosoto (https://keybase.io/leosoto) on keybase.
  • I have a public key ASDyLzlvoCybHS40pZ96Hqo3dRJAEtUN9tEely8XiK6ldQo

To claim this, I am signing this object:

@leosoto
leosoto / bb2gh.sh
Created April 2, 2018 13:49
Moves all your organization's bitbucket repositories to GitHub. Note that when a repository is correctly uploaded to GitHub it is *removed* from BitBucket. Requires https://bitbucket.org/zhemao/bitbucket-cli/. Set the variables BB_* with your bitbucket credentials and GH_* variables with your GitHub credentials.
#!/bin/bash
set -e
repos=$(bb list -u $BB_USERNAME -p $BB_PASSWORD --private | grep $BB_ORG | cut -d' ' -f3 | cut -d'/' -f2)
for repo in $repos; do
echo
echo "* Processing $repo..."
echo
git clone --bare git@bitbucket.org:$BB_ORG/$repo.git
cd $repo.git
echo
require 'benchmark'
str = "<p>"
50.times do
str += " "
elapsed_time = Benchmark.measure {
str.gsub(/\<p\>(\<br\s*\/?\>|\s+)*<\/p\>/, '')
}.utime
puts "largo: #{str.length}; tiempo: #{elapsed_time}"
end
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-1.9.3-jruby-1.7.9
-----> Installing JVM: openjdk7-latest
-----> Installing dependencies using 1.5.2
Ruby version change detected. Clearing bundler cache.
Old: jruby 1.7.9 (1.9.3p392) 2013-12-10 fffffff on OpenJDK 64-Bit Server VM 1.7.0_45-b31 [linux-amd64]
New: jruby 1.7.9 (1.9.3p392) 2013-12-10 fffffff on OpenJDK 64-Bit Server VM 1.6.0_27-b27 [linux-amd64]
sh: Syntax error: EOF in backquote substitution
sh: Syntax error: EOF in backquote substitution