-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6348d8c
commit a76b3c1
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...ts/2024/2024-08-23 Fixing problem with ODBC connection in RStudio on Mac M1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` | ||
```` |
16 changes: 16 additions & 0 deletions
16
content/posts/2024/2024-09-04 Tracking Word Count Progress in Git.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |