Skip to content

Commit

Permalink
feat: post about word counting
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltomasz committed Sep 5, 2024
1 parent 6348d8c commit a76b3c1
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "Fixing problem with ODBC connection in RStudio on Mac M1"
description: "Fixing problems with ODBC connections"
url: "/2024/odbc-mac-m1"
date: "2024-08-24T1:00:00-07:00"
draft: true
tags: [til, odbc,sql, R]
---

Example QMD file below:

````
---
title: "SQLite Database Creation and Connection Demo"
format: html
editor: visual
---
## Setup
First, we'll load the necessary libraries and set up our file paths.
```{r setup}
#| message: false
#| warning: false
Sys.setenv(ODBCSYSINI = "/opt/homebrew/etc")
library(RSQLite)
library(DBI)
library(odbc)
library(here)
# Define the database file path
db_path <here::here("sample_database.sqlite")
# Print the database path for verification
print(paste("Database path:", db_path))
```
## Create SQLite Database and Add Dummy Data
Now, let's create a SQLite database and populate it with some dummy data.
```{r create_db}
# Create a connection to a new SQLite database
con <dbConnect(RSQLite::SQLite(), dbname = db_path)
# Create a table
dbExecute(con, "CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY,
name TEXT,
department TEXT,
salary REAL
)")
# Create some dummy data
employees <data.frame(
name = c("Alice", "Bob", "Charlie", "David", "Eve"),
department = c("HR", "IT", "Sales", "Marketing", "Finance"),
salary = c(50000, 60000, 55000, 52000, 58000)
)
# Insert the dummy data into the table
dbWriteTable(con, "employees", employees, append = TRUE)
# Verify the data
result <dbGetQuery(con, "SELECT * FROM employees")
print(result)
# Close the connection
dbDisconnect(con)
```
## Connect to SQLite Database using ODBC
Now that we have created our SQLite database, let's connect to it using ODBC.
```{r odbc_connect}
# Create the connection string
conn_string <paste0("Driver={SQLite3};Database=", db_path, ";")
# Create an ODBC connection
con_odbc <dbConnect(odbc::odbc(), .connection_string = conn_string)
# This connection should now appear in the Connections pane
# Verify the connection by querying the data
result_odbc <dbGetQuery(con_odbc, "SELECT * FROM employees")
print(result_odbc)
# Don't forget to close the connection when you're done
dbDisconnect(con_odbc)
```
## Cleanup
If you want to remove the database file after running this demo, uncomment and run the following code:
```{r cleanup}
# Remove the database file
# file.remove(db_path)
```
````
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Tracking Word Count Progress in Git"
description: "Count your progres with Typst project"
url: "/2024/count-progress-git"
date: "2024-09-05T1:00:00-07:00"
draft: false
tags: [git, typst,bash, productivity]
---

I created a simple script to count word changes in my git repository. I'm trying Typst now for writing an article in VSCode, and there's no good extension to quantify daily progress. This script looks at your commits, counts words added, deleted, and duplicated in  the files of  the extension by  your choice (by default .typ and .md files). It shows a daily breakdown of writing progress.

Got the idea from a [Gijs van Dam's blog post ](//www.gijsvandam.nl/post/measuring-your-writing-progress-with-a-git-word-count/) (who described logic behind the word change calculation). I adapted it by adding Typst and extending the way it display the output. I add some additions like handling the first commit: The script checks if it's dealing with the first commit in the repo, which doesn't have a parent to compare against and it stops.

It's been helpful for tracking my word count (and writing it was a nice excuse to not writing the text I supposed to write). Below you can find the gist with the latest version.

[https://gist.github.com/danieltomasz/e3be94d7f03ade2eb030edf63920e95a](https://gist.github.com/danieltomasz/e3be94d7f03ade2eb030edf63920e95a)

0 comments on commit a76b3c1

Please sign in to comment.