Skip to content

Instantly share code, notes, and snippets.

View AlexRiedler's full-sized avatar

Alex Riedler AlexRiedler

View GitHub Profile
@AlexRiedler
AlexRiedler / read_csv.py
Created May 10, 2024 01:04
Read CSV in Python
import sys
import csv
import json
with open(sys.argv[1], 'r' ) as file:
reader = csv.DictReader(file)
for obj in reader:
# transform
new_obj = {
obj['table']: {
@AlexRiedler
AlexRiedler / redshift_to_spark.py
Created April 21, 2024 23:44
sqlglot converters
#!/usr/bin/env python
import sqlglot
from sqlglot.optimizer import optimize
import sys
query = sys.stdin.read()
query = optimize(sqlglot.parse_one(query)).sql(pretty=True)
query = sqlglot.transpile(query, read="redshift", write="spark2", pretty=True)[0]
@AlexRiedler
AlexRiedler / PERF.md
Created July 29, 2023 20:09
Rails Performance

Performance Tests

NOTE:

  • tests were ran on an m1 macbook pro with 32gb of memory
  • clean rails install via rails new app --api -d=postgresql
  • puma is running in 5:5 production single mode (the default)
  • results were ran 2-times to get any caches and loading ignored

Initial Test 404, no routes

@AlexRiedler
AlexRiedler / bundling_both.txt
Created February 4, 2016 22:25
Bundler #4276 output logs
(fails)
$ dbundle env
Environment
Bundler 1.12.0.pre
Rubygems 2.4.5.1
Ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
Git 2.1.4
Gemfile
@AlexRiedler
AlexRiedler / example.rb
Last active September 23, 2015 02:42
Sequel + Arel (not a good idea, but is possible)
require "sequel_arel"
require "sequel"
sequel_db = # ...
sql_arel_connection = SequelConnection.new(sequel_db)
sequel_engine = SequelEngine.new(sql_arel_connection)
users = Arel::Table.new(:users)
users.engine = sequel_engine
#!/bin/bash -ex
echo "installing homebrew"
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
echo "Installing Packages with Homebrew"
brew install ack autoconf automake curl \
coreutils brew-cask git libxml2 libxslt \
libyaml libpng libtiff libffi node openssl \
sqlite s3cmd zsh
---
- name: "Check for Existing EC2 Instances"
hosts: "building_{{app_environment}}"
tasks:
- name: Gather facts
action: ec2_facts
tags: ami
- name: Add existing instance to launched groups
local_action: add_host hostname="{{ansible_ec2_public_hostname}}" groups="webservers,{{app_environment}},launched"
register: existing_instance
diff --git a/Vagrantfile b/Vagrantfile
index eb7fff2..686a706 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -14,6 +14,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
+ # see https://github.com/mitchellh/vagrant/issues/391 (ssh issues on reload)
+ v.customize ["modifyvm", :id, "--natnet1", "192.168/16"] # setup nat networking
gulp.task "rev", ["images", "fonts", "scripts", "styles"], ->
return unless config.production # we do not need to do anything
# grab all the assets that don't need modified but should be reved
reved_suffix = ".rev"
return gulp.src(
[
"#{static_output_dir}/**/*.{css,js,jpeg,jpg,svg,gif,png,eot,woff,ttf}",
# exclude already reved files (previous versions, etc)
"!#{static_output_dir}/**/*#{reved_suffix}.{css,js,jpeg,jpg,svg,gif,png,eot,woff,ttf}"
], { base: __dirname })
@AlexRiedler
AlexRiedler / structure.txt
Created May 31, 2014 17:11
GulpJS advanced setup
Folder Structure:
Option 1:
- requires multiple gulpfile, or some weird path parsing for changes
/shared/
/product/shared/{styles,index.html,scripts, templates}
/product/company/themes/{styles,index.html,scripts, templates}
/product/company/shared/{styles,index.html,scripts, templates}