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 / 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',

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)))
@andrerocker
andrerocker / 256color.pl
Created November 21, 2014 04:12
256 color test
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $
# use the resources for colors 0-15 - usually more-or-less a
# reproduction of the standard ANSI colors, but possibly more
# pleasing shades
# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
@andrerocker
andrerocker / Serializer.java
Created September 26, 2014 04:48
Serialize and unserialize any java object to a base46 string
private String serialize(Object object) {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream output = new ObjectOutputStream(buffer);
output.writeObject(object);
output.flush();
return Base64.encodeBase64String(buffer.toByteArray());
} catch (Exception e) {
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) }