Skip to content

Instantly share code, notes, and snippets.

@drincruz
drincruz / db_row_generator.py
Created August 22, 2014 16:17
Simple example of using a Python generator to fetch a row from a MySQL database
#!/usr/bin/env python
"""
Here is a simple example of how you can
use a generator to fetch a row from a database
"""
import MySQLdb
@drincruz
drincruz / .gitconfig
Created June 6, 2022 14:53
Git configs to support multiple environments and separate files
[core]
excludesfile = ~/.gitignore_global
[user]
name = Adrian Cruz
email = my-work-email@work.com
signingkey = work-signing-key
[gpg]
program = /usr/local/bin/gpg
# Include custom .gitconfig if in personal github dir
@drincruz
drincruz / fibonacci.ex
Last active April 11, 2022 18:23
What Fibonacci looks like in Elixir
defmodule ElixirLab.Fibonacci do
# Recursive
def fib(0), do: 1
def fib(1), do: 1
def fib(n), do: fib(n-1) + fib(n-2)
# Iterative
def iter_fib(0), do: 1
def iter_fib(1), do: 1
def iter_fib(index) do
@drincruz
drincruz / fast_video_x.js
Created September 30, 2020 21:26
Play video on a page at a faster rate
document.querySelector('video').playbackRate = 1.75;
@drincruz
drincruz / aws.cli.ec2.instances.sh
Created November 29, 2019 04:34
aws CLI Helpful commands
# Output the Public IP, Private IP, Instance Name
aws --profile default ec2 describe-instances --query 'Reservations[].Instances[].[PublicIpAddress,PrivateIpAddress,Tags[?Key==`Name`]| [0].Value]' --output=table
@drincruz
drincruz / gohang.go
Created June 18, 2019 21:08
Quick Golang HTTP Server
package main
import (
"fmt"
"time"
"net/http"
)
func main() {
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
@drincruz
drincruz / fizz_buzz.ex
Created March 14, 2017 18:32
FizzBuzz in Elixir and Python
def fizz_buzz(n) when 0 === rem(n, 3) and 0 === rem(n, 5) do
"FizzBuzz"
end
def fizz_buzz(n) when 0 === rem(n, 3), do: "Fizz"
def fizz_buzz(n) when 0 === rem(n, 5), do: "Buzz"
def fizz_buzz(n), do: n
@drincruz
drincruz / 15-xdebug.ini
Created June 2, 2016 19:32
Xdebug and Vagrant
; Enable xdebug extension module
zend_extension=xdebug.so
; see http://xdebug.org/docs/all_settings
xdebug.remote_enable = 1
xdebug.remote_host = 10.0.2.2
xdebug.remote_port = 9000
xdebug.idekey = "vagrant"
xdebug.remote_handler = dbgp
@drincruz
drincruz / hacker_news_standard_deviation.sql
Last active April 29, 2016 10:12
Getting variance and standard deviation in BigQuery
SELECT
variance,
standard_deviation,
input
FROM (standardDeviation(
SELECT
'[' + GROUP_CONCAT_UNQUOTED(STRING(score)) + ']' AS json_array_input
FROM (
SELECT
score
@drincruz
drincruz / tmp.json
Last active April 18, 2016 18:11
Python JSON to CSV via Pandas
{"col0":{"0":0,"1":1,"2":2,"3":3,"4":4},"col1":{"0":4,"1":3,"2":2,"3":1,"4":0},"col2":{"0":5,"1":6,"2":7,"3":8,"4":9}}