Skip to content

Instantly share code, notes, and snippets.

View jgomo3's full-sized avatar
🏠
Working from home

Jesús Gómez jgomo3

🏠
Working from home
View GitHub Profile
@jgomo3
jgomo3 / seeds.rb
Created July 11, 2018 13:34 — forked from seyhunak/seeds.rb
Rails - Import SQL file as seed
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
@jgomo3
jgomo3 / infix.clj
Last active April 18, 2018 16:44
Last exercise of the Read and Eval Chapter of Brave Clojre
(ns infix)
(defn index-of
"Clojure doesn't have an index-of function. The Java .indexOf method
works reliably for vectors and strings, but not for lists. This solution
works for all three.
https://stackoverflow.com/a/37858115/344501
"
[item coll]
(let [v (if
@jgomo3
jgomo3 / compose.py
Last active April 5, 2018 13:51
Function composition and piping (or chaining) using reduce
from functools import partial
from functools import reduce
def _chain(order, *functions):
ordered_functions = list(order(functions))
first_fn = ordered_functions[0]
rest_fn = ordered_functions[1:]
def _apply(x, f):
return f(x)
def composite(*args, **kwargs):
@jgomo3
jgomo3 / flush-dns.sh
Created March 19, 2018 17:50 — forked from craigvantonder/flush-dns.sh
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart
@jgomo3
jgomo3 / smash_hobbits.clj
Created March 16, 2018 03:03
Chapter 3 excercise for the "Clojure for the Brave and True" -- For hitting hobbits
(ns clojure-noob.smash-hobbits
(:require [clojure.string :as str]))
(def asym-hobbit-body-parts [{:name "head" :size 3}
{:name "left-eye" :size 1}
{:name "left-ear" :size 1}
{:name "mouth" :size 1}
{:name "nose" :size 1}
{:name "neck" :size 2}
{:name "left-shoulder" :size 3}
@jgomo3
jgomo3 / delete-from-repo.md
Created March 12, 2018 14:08 — forked from scy/delete-from-repo.md
How to delete a file from a Git repository, but not other users' working copies

How to delete a file from a Git repository, but not other users' working copies

Suppose you have, by mistake, added your IDE's project folder (you know, these .idea folders with all kinds of local paths and configuration data and settings in it) to the Git repository of your project. (We're talking about a whole folder here, but the same rules apply to individual files as well.)

Of course, you only realize that two days after the fact and have already pushed it, and your colleagues have already pulled it. They use the same IDE as you do, so whenever they change a setting or fix paths, they can either

  • commit that, causing nasty merge conflicts for you and others or
  • ignore the changes and carry around a modified file until the end of time without ever committing it.

Why .gitignore won't help

@jgomo3
jgomo3 / explode.rb
Last active February 28, 2018 00:03
Returns the string after resolving all the references the strings do
# Given a table of strings, which could reference any other string in the table,
# returns the string after resolving all the references.
# Example:
# table = {a: 'ツ', b: '(%{a})', c1: '¯\_', c2: '_/¯', o: '%{c1}%{b}%{c2}'}
# explode_key(table, :o) => ¯\_(ツ)_/¯
# It doesn't allow circular references.
def explode_key(keys_table, key)
partial_string = keys_table[key]
allowed_loops = keys_table.keys.length # [1]

Keybase proof

I hereby claim:

  • I am jgomo3 on github.
  • I am jgomo3 (https://keybase.io/jgomo3) on keybase.
  • I have a public key whose fingerprint is E8CA 7677 6DF0 F87E 23D7 21DA BE66 27F0 D1C6 243A

To claim this, I am signing this object:

@jgomo3
jgomo3 / schema_clone.py
Created June 7, 2017 18:39 — forked from rabbitt/schema_clone.py
PostgreSQL schema cloner (including data).
import psycopg2 as pg
from io import BytesIO
from collections import defaultdict
from contextlib import contextmanager
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED
READ_COMMIT = ISOLATION_LEVEL_READ_COMMITTED
AUTO_COMMIT = ISOLATION_LEVEL_AUTOCOMMIT
@jgomo3
jgomo3 / consolidar.sh
Created May 17, 2017 18:20
Concatena todos los PDF de una carpeta
#!/bin/sh
# consolidar.sh
#
# 10 de junio de 2016
# Concatena a los pdf de la carpeta `Preliminares` los pdf
# correspondientes con el mismo nombre en la carpeta `Respuestas`
# y el resultado lo genera con el mismo nombre en la carpeta
# Consolidados.
#