Skip to content

Instantly share code, notes, and snippets.

View andrerocker's full-sized avatar
🤓
Clojure / SRE

Andre Souza andrerocker

🤓
Clojure / SRE
View GitHub Profile
@andrerocker
andrerocker / 1.js
Last active January 27, 2023 19:34
react + google-maps: @googlemaps/react-wrapper (Yes It's really need at least two components)
import { Wrapper } from "@googlemaps/react-wrapper";
const ParentComponentThatWillReceiveGoogleMap = () => {
return <Wrapper apiKey={"42-l337-lol-bbq"}>
<MyGoogleMapComponent/>
</Wrapper>
}
@andrerocker
andrerocker / clojure-check-jpg-using-cats.clj
Last active January 13, 2022 20:36
clojure: check if a file is a valid jpg file
;; Using javax.imageio and funcool/cats
;; it's leaking fds, take care!
(defn valid-jpg-image? [image-url]
(let [image-input (-> image-url io/input-stream ImageIO/createImageInputStream)
encoders (-> (ImageIO/getImageReadersByFormatName "jpg") iterator-seq)
image-result (map #(either/try-either (doto % (.setInput image-input) (.read 0))) encoders)]
(->> image-result either/rights not-empty boolean)))
@andrerocker
andrerocker / sqlserver-dump-only-data.ps1
Created October 30, 2010 22:36
Powershell Script to: Export ONLY the data from yours SQLServer like mysqldump
$database_host = "<host>"
$database_name = "<database>"
$output_file = "<output_file>"
$user = "<username>"
$password = "<password>"
[system.reflection.assembly]::loadWithPartialName('Microsoft.SqlServer.SMO')
$server = new-object "Microsoft.SqlServer.Management.Smo.Server" $database_host
$server.connectionContext.loginSecure = $false
$server.connectionContext.set_Login($user)
@andrerocker
andrerocker / cockroachdb-ruby-pg-sample.rb
Last active February 15, 2018 22:55
ruby cockroachdb pg sample
def connection
@conn ||= PG.connect({
host: ARGV.first,
port: 26257,
dbname: 'cocksparrer',
user: 'root',
sslmode: 'require',
sslrootcert: 'util/certs/cock-master/ca.crt',
sslcert: 'util/certs/cock-master/client.root.crt',
sslkey: 'util/certs/cock-master/client.root.key',
@andrerocker
andrerocker / sqlserver-dump.ps1
Created October 30, 2010 22:12
Powershell Script to: Export all data from yours SQLServer like mysqldump
$database_host = "<host>"
$database_name = "<database>"
$output_file = "<output_file>"
$user = "<username>"
$password = "<password>"
[system.reflection.assembly]::loadWithPartialName('Microsoft.SqlServer.SMO')
$server = new-object "Microsoft.SqlServer.Management.Smo.Server" $database_host
$server.connectionContext.loginSecure = $false

Effective Engineer - Notes

What's an Effective Engineer?

  • They are the people who get things done. Effective Engineers produce results.

Adopt the Right Mindsets

#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@andrerocker
andrerocker / threads.py
Created November 6, 2015 17:14
python threads cpu gil
import threading
def cegela():
while True:
pass
map(lambda y: y.start(), map(lambda x: threading.Thread(target=cegela), range(0,4)))
mysql> use rails_girls_sp;
Database changed
mysql> select count(sex) count, sex from persons group by sex;
+--------+------+
| number | sex |
+--------+------+
| 1887 | M |
| 3 | F |
+--------+------+
2 rows in set, 1 warning (0.00 sec)
@andrerocker
andrerocker / gist:1086891
Created July 16, 2011 22:56
vitae.me resque conf
require 'resque/tasks'
require 'active_record'
env = ENV["RAILS_ENV"] || 'development'
database_config = YAML::load(File.open('config/database.yml'))
connection = ActiveRecord::Base.establish_connection(database_config[env])
files = ['app/models/profile', 'app/workers/avatar']
files.each { |file| require File.expand_path(file) }