Skip to content

Instantly share code, notes, and snippets.

View herval's full-sized avatar
:shipit:

Herval Freire herval

:shipit:
View GitHub Profile
### Keybase proof
I hereby claim:
* I am herval on github.
* I am herval (https://keybase.io/herval) on keybase.
* I have a public key ASD9Cs4lUm0LtcLwHZqssHZEH3A6w3WWC_H7jul4nrRLHQo
To claim this, I am signing this object:
@herval
herval / main.cpp
Created March 18, 2017 04:48
C++11 syntax & stuff
#include <iostream>
// template (generics)
template<typename F>
auto &f(F &param) {
return param;
}
// TODO reflection
// TODO type casting/switching
@herval
herval / int_additions.scala
Created April 18, 2016 14:37
Manipulating maps with Monoids
object MindBlown extends App {
trait Monoid[A] {
def op(a1: A, a2: A): A
def zero: A
}
val intAddition = new Monoid[Int] {
override def op(a1: Int, a2: Int) = a1 + a2
override def zero = 0
}
@herval
herval / shakespeare_rnn.txt
Created October 28, 2015 08:56
Shakespeare generator LSTM RNN
Output from https://github.com/deeplearning4j/dl4j-0.4-examples/blob/master/src/main/java/org/deeplearning4j/examples/rnn/GravesLSTMCharModellingExample.java
Using existing text file at /var/folders/zs/vsf7sw7540s3jrqjf8ty0jfc0000gp/T/Shakespeare.txt
Loaded and converted file: 5459809 valid characters of 5465100 total characters (5291 removed)
22:37:27.108 [main] DEBUG org.reflections.Reflections - going to scan these urls:
jar:file:/Users/herval/.gradle/caches/modules-2/files-2.1/org.nd4j/nd4j-jblas/0.4-rc3.4/1548e2f266bab6e5bc1a5cd3161c4c850c0059c9/nd4j-jblas-0.4-rc3.4.jar!/
jar:file:/Users/herval/.gradle/caches/modules-2/files-2.1/org.nd4j/nd4j-api/0.4-rc3.5/9c16cbc97c0da0dba3b1a9fe4fc2efcfa6d689c1/nd4j-api-0.4-rc3.5.jar!/
jar:file:/Users/herval/.gradle/caches/modules-2/files-2.1/org.nd4j/nd4j-bytebuddy/0.4-rc3.5/e8c11225c9ef69166c328c0b97335f54f3af1955/nd4j-bytebuddy-0.4-rc3.5.jar!/
22:37:27.263 [main] INFO org.reflections.Reflections - Reflections took 148 ms to scan 3 urls, producing 82 keys and 375 v
@herval
herval / stackfile.yml
Last active May 13, 2016 05:00
Daily Postgres Backup from Tutum to S3
backup:
image: 'borja/dockup:latest'
environment:
- AWS_ACCESS_KEY_ID=<SET ME>
- AWS_DEFAULT_REGION=<SET ME>
- AWS_SECRET_ACCESS_KEY=<SET ME>
- BACKUP_NAME=<SET ME>
- PATHS_TO_BACKUP=/var/lib/postgresql/data
- S3_BUCKET_NAME=<SET ME>
restart: on-failure
@herval
herval / rds_to_docker.md
Last active June 4, 2024 13:30
Moving a Postgres db from RDS to a Docker container

Make a backup from RDS

pg_dump -h <rds host> -p 5432 -F c -O -U <rds user> <db name> > db.dump

Restore the backup into a Docker container

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_restore --verbose --clean --no-acl --no-owner -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name> /tmp/db.dump'
class Entity < Struct.new(:name, :ratings)
end
@gamers = [
Entity.new('Lisa', {
'Prince of Persia' => 2.5,
'Doom' => 3.5,
'Castle Wolfenstein' => 3.0,
'Rise of the Triad' => 3.5,
'Commander Keen' => 2.5,
@herval
herval / each_hash_inject.rb
Created September 25, 2012 21:45
Comparing each, Hash[] and inject performance
require 'benchmark'
runs = 1000
original_data = {}
1000.times do |t| # 1000 depts with 100 guys each
original_data["dept_#{t}"] = (1..100).to_a
end
def employee_name(id)
curl -i -H "Accept: application/json" -X POST -d "title=<bug title>&access_token=<your access token>" https://api.github.com/repos/<username>/<your repo>/issues
@herval
herval / gist:2044137
Created March 15, 2012 13:13
My .bash_profile prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# <rvm_ruby@gemset> (<git branch, if in a git folder>) @ <current path in disk>
PS1='\[\e[0;32m\]$(~/.rvm/bin/rvm-prompt i v g) $(parse_git_branch)\[\e[m\] @ \[\e[1;34m\]\w\[\e[m\] \[\e[m\]
\[\e[1;32m\]\$ \[\e[m\]\[\e[m\] '