Skip to content

Instantly share code, notes, and snippets.

View nbenn's full-sized avatar
👻

Nicolas Bennett nbenn

👻
View GitHub Profile
@nbenn
nbenn / gitea.log
Created July 15, 2023 12:30
Gitea create user log
2023/07/15 09:04:24 models/user/user.go:696:CountUsers() [I] [SQL] SELECT count(*) FROM `user` WHERE type=? [0] - 5.220318ms
2023/07/15 09:04:24 .../cli@v1.22.10/app.go:524:HandleAction() [I] [SQL] BEGIN TRANSACTION [] - 67.022µs
2023/07/15 09:04:24 models/user/user.go:482:IsUserExist() [I] [SQL] SELECT `id`, `lower_name`, `name`, `full_name`, `email`, `keep_email_private`, `email_notifications_preference`, `passwd`, `passwd_hash_algo`, `must_change_password`, `login_type`, `login_source`, `login_name`, `type`, `location`, `website`, `rands`, `salt`, `language`, `description`, `created_unix`, `updated_unix`, `last_login_unix`, `last_repo_visibility`, `max_repo_creation`, `is_active`, `is_admin`, `is_restricted`, `allow_git_hook`, `allow_import_local`, `allow_create_organization`, `prohibit_login`, `avatar`, `avatar_email`, `use_custom_avatar`, `num_followers`, `num_following`, `num_stars`, `num_repos`, `num_teams`, `num_members`, `visibility`, `repo_admin_change_team_access`, `diff_view_style`, `theme`, `keep
@nbenn
nbenn / use_of_reactive.R
Created April 22, 2023 09:32
Simple DT/reactive example
##### Use of reactive() #####
library(shiny)
library(dplyr)
library(DT)
dt <- data.frame(
id = c(1, 1, 2),
text = c("text1", "text2", "text1")
)
@nbenn
nbenn / test-tz.R
Created February 11, 2023 08:12
Minimal shiny app for investigating TZ issues
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
@nbenn
nbenn / pq_auto_increment.R
Created November 10, 2022 15:20
Auto increment for Postgres (for use within a package)
#' @importFrom methods setOldClass setMethod
#' @importMethodsFrom DBI dbDataType
#' @importClassesFrom RPostgres PqConnection
#' Generate SQL for custom data types
#'
#' SQL for data types as described in [auto_increment()] can be generated
#' using [DBI::dbDataType()].
#'
#' @param dbObj Object for determining SQL dialect (e.g. connection)
@nbenn
nbenn / topo_sort_dm.R
Created November 10, 2022 15:14
Topo sort dm
dfs <- function(x, child, parent) {
visit <- function(i) {
if (perm[i]) {
return(NULL)
}
if (temp[i]) stop("Not a DAG")
temp[i] <<- TRUE
@nbenn
nbenn / dtw-py-vs-r.R
Created August 22, 2019 06:33
Comparison of python tslearn and R dtw implementations
library(reticulate)
library(dtw)
use_condaenv("dtw")
tslearn <- import("tslearn")
tslearn$metrics$dtw(rep(0, 3), 1:4)
dtw(rep(0, 3), 1:4, keep.internals = T, step.pattern = symmetric1)[
@nbenn
nbenn / mp11-functor-recursion.cpp
Created August 6, 2019 18:03
Runtime index for choosing type
// compile: clang++ -Wall -std=c++11 -I /usr/local/include mp11.cpp -o mp11
#include <vector>
#include <iostream>
#include <stdexcept>
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/algorithm.hpp>
@nbenn
nbenn / functor-recursive-switch.cpp
Last active August 5, 2019 15:16
Runtime index for choosing type
#include <stdexcept>
#include <tuple>
#include <iostream>
// terminating case to avoid if-constexpr
template <template<class> class F, typename R, typename... Ar>
R dispatch_impl(int, Ar&&... rgs) {
throw std::runtime_error("error");
}
@nbenn
nbenn / functor-type-switch.cpp
Last active August 4, 2019 12:38
Runtime index for choosing type
// compile: clang++ -Wall -std=c++11 functor-type-switch.cpp -o functor-type-switch
#include <vector>
#include <iostream>
#include <stdexcept>
template <template<typename> class Func, typename ...Ar>
auto dispatch_type(size_t type, Ar&&... rg) ->
decltype(Func<int>()(std::forward<Ar>(rg)...)) {
switch(type) {
@nbenn
nbenn / mp11-type-list-switch.cpp
Last active August 4, 2019 12:27
Runtime index for choosing type
// compile: clang++ -Wall -std=c++14 -I /usr/local/include mp11-type-list-switch.cpp -o mp11-type-list-switch
#include <vector>
#include <iostream>
#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>
namespace mp11 = boost::mp11;