Skip to content

Instantly share code, notes, and snippets.

@ernesthan
ernesthan / postgres-brew.md
Created September 10, 2020 05:35 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
### Source: https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them
list.of.packages <- c(
"tidyverse", # Packages included: ggplot2, purr, tibble, dplyr, tidyr, stringr, readr, forcats
"readxl", # read_excel()
"writexl", # write_xlsx()
"stargazer",
"ggthemes",
"usethis"
)
@ernesthan
ernesthan / TelegramSendMessage.R
Created February 5, 2020 09:39
Telegram Send Message (with R)
## Requires HTTR package
if (!require('httr')) install.packages('httr'); library('httr')
## Replace following variables: DEFAULT_CHAT_ID, DEFAULT_BOT_TOKEN
sendMessage <- function(
text=stop("Text parameter is required!"),
chat_id=DEFAULT_CHAT_ID,
bot_token=DEFAULT_BOT_TOKEN,
...
@ernesthan
ernesthan / mac-cpu-model.sh
Created November 20, 2018 02:03
Find what's your mac CPU processor
sysctl -n machdep.cpu.brand_string
# Source: https://www.tekrevue.com/tip/find-mac-cpu-model/
<<external-code, cache=FALSE>>=
read_chunk('foo-bar.R')
@
@ernesthan
ernesthan / laravel-clear-cache
Created September 20, 2017 02:56
Clear config and reload .env, clear cache.
php artisan config:clear
php artisan cache:clear
@ernesthan
ernesthan / laravel-lazy-load.php
Created September 5, 2017 11:29
Listen to queries happening on Laravel DB
DB::listen(function($query) {
var_dump($query->sql);
});
// Retrieves all notes in card first
$card->notes->first();
$card->notes()->first(); // Build query first then retrieve with Limit 1
//Note that Laravel caches the query result, so first case may be better sometimes.
@ernesthan
ernesthan / LogisticFunction.r
Created July 20, 2017 04:12
Logistic Function in R
# Logistic Function
logistic <- function(x, L=1, k=1, sigmoidMid=0) {
return(L / (1 + exp(-k*(x-sigmoidMid))))
}
# Testing the function
x = seq(from=-10, to=10, by=1)
plot(x=x, y=logistic(x))
lines(x=x, y=logistic(x))
@ernesthan
ernesthan / changeRDefaultLocale.sh
Last active July 16, 2017 03:55
Force R locale to en_US.UTF-8 to remove the warning message from R Start-up (Run from terminal)
defaults write org.R-project.R force.LANG en_US.UTF-8
@ernesthan
ernesthan / config.cson
Created April 23, 2017 08:01
Atom Softwrap by default
editor:
softWrap: true