Skip to content

Instantly share code, notes, and snippets.

View inkrement's full-sized avatar

Christian Hotz-Behofsits inkrement

View GitHub Profile

SQL Introduction (DuckDB)

Expressions: Values, Operators and Functions

Expressions are the elementar building-blocks of SQL-Queries; most SQL-Clauses (e.g., SELECT, WHERE) use them as arguments. An expression is either a value (e.g., 3, 2.3, 'hello world' or column_name), an operator (e.g., +, -, /), or a function (e.g., my_function()).

Some operations, and most functions, work only on specific data types. For example, there are a number of operators and functions specifically for dates and strings.

Data types

cosine_similarity <- function(a,b){
# assuming unit vectors
# the cosine is just the dot-product
a %*% b
}
most_similar <- function(embeddings, ref_item, n_top = 10){
# calculate cos similarity to ref_item for all elements
cos_sims <- eapply(embeddings, cosine_similarity, b = ref_item)
load_embedding <- function(file_path){
# load full file
lines <- readLines(file_path)
 
# create new environment
embeddings_env <- new.env(hash = TRUE, parent = emptyenv())
 
# this function is used to convert vectors to unit vectors
# by dividing their components by vector length
normalize_vector <- function(a){
@inkrement
inkrement / baseR_embeddings.R
Last active March 12, 2024 11:44
Some R functions to load *.vec files (used for distributed Word Embeddings).
load_embedding <- function(file_path){
# load full file
lines <- readLines(file_path)
# create new environment
embeddings_env <- new.env(hash = TRUE, parent = emptyenv())
# this function is used to convert vectors to unit vectors
# by dividing their components by vector length
version: '2'
services:
caddy:
image: joshix/caddy
links:
- rstudio
volumes:
- ./site/:/var/www/html
- ./.caddy/:/.caddy
ports:
@inkrement
inkrement / clickhousedump
Created August 19, 2017 14:26
dump all clickhouse databases and tables
#!/bin/bash
OUTDIR=.
while read -r db ; do
while read -r table ; do
if [ "$db" == "system" ]; then
echo "skip system db"
continue 2;
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
UCgefQJC5UgbWJHDxBqB4qVg
UC0v-tlzsn0QZwJnkiaUSJVQ
UCo_IB5145EVNcf8hw1Kku7w
UC-lHJZR3Gqxm24_Vd_AJ5Yw
UCGjylN-4QCpn8XJ1uY-UOgA
UCGCPAOQDZa_TTTXDr5byjww
UC4PooiX37Pld1T8J5SYT-SQ
UCJZ7f6NQzGKZnFXzFW9y9UQ
UCfm4y4rHF5HGrSr-qbvOwOg
UCHUE4ypXKp7ZkmdWbGJNgJg
<?php
date_default_timezone_set('UTC');
require 'vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
@inkrement
inkrement / my.cnf
Last active April 25, 2016 12:44
Scaleway VP1 optimised mysql configuration - used Percona Configuration Wizard (http://tools.percona.com/)
[mysql]
local-infile=1 ## enable local infile support
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
@inkrement
inkrement / .htaccess
Created April 8, 2016 10:34
octobercms_serverpilot
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
##
## You may need to uncomment the following line for some hosting environments,