Skip to content

Instantly share code, notes, and snippets.

View honzasterba's full-sized avatar

Honza Sterba honzasterba

View GitHub Profile
@honzasterba
honzasterba / loader.js
Created January 13, 2024 22:04
ChatWoot with TurboDrive
<style id="woot-0" data-turbo-permanent="true"></style>
<div id="woot-1" class="woot-widget-holder woot--hide woot-elements--right" data-turbo-permanent="true"></div>
<div id="woot-2" class="woot--bubble-holder" data-turbo-permanent="true"></div>
<script>
//# sourceURL=chatwoot_loader.js
window.addEventListener('chatwoot:ready', function() {
if (!window.wootLoaded) {
window.wootLoaded = true;
function markWootElement(el, i) {
el.setAttribute('data-turbo-permanent', "true")
@honzasterba
honzasterba / mailgun_ingest_test.rb
Created October 21, 2022 09:07
mailgun ingest test
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
ruby "3.1.2"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
@honzasterba
honzasterba / retry.rb
Created August 6, 2022 11:46
retry for ActiveRecord::StatementInvalid
module DbUtils
def self.retry_with_reconnect
retried = false
begin
yield
rescue ActiveRecord::StatementInvalid => e
raise if retried
Rails.logger.info "Retrying after failed statement #{e}"
ActiveRecord::Base.connection.reconnect!
retried = true

How to migrate ActiveStorage attachments from local (file-system) storage to S3/Amazon?

There are a couple of versions of this script floating around. My inspiration has been this great article

I went through their code and found most of it is not needed and it is a relict of days long gone. Now ActiveStorage has beautiful APIs and its all quite easy.

How to use

  1. create a new service configuration for S3 named it amazon
library(plyr)
data <- read.csv("~/Downloads/ockovaci-mista.csv")
data$datum <- as.Date(data$datum)
data$week <- strftime(data$datum, format = "%Y-%V")
prvni.davka <- data[ data$poradi_davky == 1,]
by.week <- ddply(prvni.davka, .(week), .fun = function(part) {
data.frame(cnt = nrow(part))
})
add <- by.week[by.week$week == "2021-53", "cnt"]
by.week[by.week$week == "2020-53", "cnt"] = add + by.week[by.week$week == "2020-53", "cnt"]
@honzasterba
honzasterba / script.py
Created October 8, 2020 08:01
Reproducing NaN in metrics when using reg:gamma
import sys
sys.path.insert(1,"../h2o-3/h2o-py") # fix this to match your env
from tests import pyunit_utils
import importlib
import pandas as pd
import numpy as np
import xgboost as xgb
import h2o
@honzasterba
honzasterba / gist:6898282
Last active December 25, 2015 01:49
using voice synthetizer instead of my own voice
while [ 1 ] ; do found=$(curl -s http://store.apple.com/cz | grep -E 'src="[^"]+backsoon[^"]+"' | wc -l) ; if [ $found -eq "0" ] ; then while [ 1 ] ; do echo "READDDYYYYY" ; say "Apple store is open" ; done ; else echo "not yet" ; fi ; sleep 10 ; done ;
@honzasterba
honzasterba / parallel-requests.js
Created June 13, 2012 09:01
ParallelRequests
/*
This is just an exploration of idea. I don't think this solution is elegant
enough. I'm looking for something that would work without the add() and done()
methods. Something like this:
new ParallelRequests(arrayOfRequests, callbackOnFinished);
The main idea is to work around delays when I need to aggregate data from
various sources before I can do something with them. Chaining is clearly not
the right way to go.
def time_from_now_in_words(time, include_seconds = true)
distance_of_time_in_words(time, Time.now, include_seconds, :future => true)
end
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
distance_in_minutes = (((to_time - from_time).abs)/60).round
distance_in_seconds = ((to_time - from_time).abs).round
#!/bin/bash
#
# Download and install libevent and memcached from source on Debian Etch or
# Debian Lenny.
#
# Assumptions
# - libevent(1.4) and memcached have not been installed from apt repositories
# - memcached is not already running
# - it is ok to clobber scripts at
# /etc/memcached.conf