Skip to content

Instantly share code, notes, and snippets.

View sgoley's full-sized avatar

sgoley sgoley

  • Remote
View GitHub Profile
@sgoley
sgoley / keybase.md
Last active January 22, 2020 18:01
Keybase - gist

Keybase proof

I hereby claim:

  • I am sgoley on github.
  • I am sgoley (https://keybase.io/sgoley) on keybase.
  • I have a public key whose fingerprint is 01C6 62A2 DB83 7A9C 390F 1A3C E7B7 AE58 C442 0F83

To claim this, I am signing this object:

@sgoley
sgoley / app.R
Created September 22, 2017 15:55 — forked from edgararuiz-zz/app.R
library(shinydashboard)
library(dplyr)
library(dbplyr)
library(purrr)
library(shiny)
library(highcharter)
library(DT)
library(htmltools)
# Use the `config` package to get the credentials
@sgoley
sgoley / r_reinstall_libs
Created June 7, 2018 04:28
Get library list from one R installation and move to new installation
#export all packages from old installation:
ip <- as.data.frame(installed.packages())
dump("ip","ip.Rdmpd")
#install all packages into new installation:
setwd("/path/to/dumpfile")
source("ip.Rdmpd")
install.packages(ip$Package)
@sgoley
sgoley / UpdateAADDevice.ps1
Created October 21, 2019 17:51
Update Microsoft Device Active Directory Name and Owner
$deviceName = 'myDeviceName' # configure device name
$newOwner = 'user@example.com' # login name of the new user
Connect-AzureAD
# Get-AzureADDevice # if you want to list all devices
# Get-AzureADUser # if you want to list all users
$device = Get-AzureADDevice | where { $_.DisplayName -eq $deviceName }
$aduser = Get-AzureADUser | where { $_.UserPrincipalName -eq $newOwner }
@sgoley
sgoley / delete where exists in list.cls
Created October 21, 2019 17:54
Salesforce Anon Apex to delete from connected object through lookup on child
//Make a list of ID's of addresses on Suppliers : List 1
List< Supplier__c > supList = [ SELECT Id,Address__c FROM Supplier__c ];
List<Id> supids = new List<Id>(new Map<Address__c,Supplier__c>(supList).keySet());
//Make a list of all address IDs : List 2
List< Address__c > AdrList = [ SELECT Id FROM Address__c ];
List<Id> adrids = new List<Id>(new Map<Id,Address__c>(AdrList).keySet());
//Make a list of ID's in List 2 which are not in List 1 : List 3
list< Id > List3 =[ SELECT Id FROM Address__c where Id not in:adrids Limit 1];
@sgoley
sgoley / Heroku env variables copy
Last active June 19, 2020 13:17
Heroku: Copying environment variables from an existing app to another
1. Export existing app’s variables to config.txt
heroku config -s -a existing-heroku-app > config.txt
2. Review and push to another app
cat config.txt | tr '\n' ' ' | xargs heroku config:set -a new-heroku-app
Credit: https://emirkarsiyakali.com/@EmirKarsiyakali
@sgoley
sgoley / condaenv.txt
Created June 24, 2020 16:42 — forked from pratos/condaenv.txt
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
@sgoley
sgoley / grant_select_on_schemas.sql
Created August 19, 2020 01:50
dbt macro to grant select usage and select for all tables of a schema
{% macro grant_select_on_schemas(schemas, user) %}
{% for schema in schemas %}
grant usage on schema {{ schema }} to "{{ user }}";
grant select on all tables in schema {{ schema }} to "{{ user }}";
alter default privileges in schema {{ schema }}
grant select on tables to "{{ user }}";
{% endfor %}
{% endmacro %}
@sgoley
sgoley / concepts_db.sql
Created August 20, 2020 15:34
Concepts database for concept / idea storage and "remixing" by Derek Sivers
-- author: Derek Sivers (https://github.com/sivers)
-- description: simple ideas / concepts / tagging table layout for PostgreSQL
CREATE TABLE concepts (
id integer primary key,
created_at date not null default CURRENT_DATE,
title varchar(127) not null unique CONSTRAINT title_not_empty CHECK (length(concepts."title") > 0),
concept text not null unique CONSTRAINT concept_not_empty CHECK (length(concepts."concept") > 0)
);
CREATE TABLE urls (
@sgoley
sgoley / create function manage_magic_timestamp_c.sql
Created August 24, 2020 02:22
easiest way to manage both "created" and "updated" timestamps on a record in postgesql
-- in schema as procedure:
create function manage_magic_timestamp_columns() returns trigger
strict
cost 1
language plpgsql
as
$$
BEGIN
-- is a new record?