Skip to content

Instantly share code, notes, and snippets.

Jesús Gómez jgomo3

Block or report user

Report or block jgomo3

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jgomo3
jgomo3 / edgelist.sql
Created Aug 9, 2019
Create an edge list of relations being related by foreign key [postgres]
View edgelist.sql
-- Pre: The names of the relations to consider are in a relation named nodes in
-- the public schema (it could be parametrized)
SELECT
tc.table_name watcher
, ctu.table_name target
FROM
information_schema.table_constraints tc
INNER JOIN information_schema.constraint_table_usage ctu ON tc.constraint_name = ctu.constraint_name
INNER JOIN nodes pt ON tc.table_name = pt."name"
@jgomo3
jgomo3 / README-oneshot-systemd-service.md
Created Jun 4, 2019 — forked from drmalex07/README-oneshot-systemd-service.md
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot
View README-oneshot-systemd-service.md

README

Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/setup-foo.sh:

@jgomo3
jgomo3 / WeatherWizard.java
Created May 29, 2019
WeatherWizard Java Tutorial example without Applets
View WeatherWizard.java
/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
@jgomo3
jgomo3 / publisher_worker_class_factory.rb
Created Apr 12, 2019
One way to wrap mundane things to a Sidekiq Worker perform method
View publisher_worker_class_factory.rb
module Notification
def self.publisher_worker_class(klass)
Class.new do
include(Sidekiq::Worker, Wisper::Publisher)
sidekiq_options(:queue => :report)
define_method :perform do |*args, **kwargs|
success = false
begin
context = klass.new.perform(*args, **kwargs)
broadcast(:deliveried_report_delivery, context)
@jgomo3
jgomo3 / my-ruby.el
Created Nov 5, 2018 — forked from littlemove/my-ruby.el
Spacemacs: Code folding for ruby-mode
View my-ruby.el
;; Code folding
(add-hook 'ruby-mode-hook
(lambda () (hs-minor-mode)))
(eval-after-load "hideshow"
'(add-to-list 'hs-special-modes-alist
`(ruby-mode
,(rx (or "def" "class" "module" "do" "{" "[")) ; Block start
,(rx (or "}" "]" "end")) ; Block end
,(rx (or "#" "=begin")) ; Comment start
@jgomo3
jgomo3 / seeds.rb
Created Jul 11, 2018 — forked from seyhunak/seeds.rb
Rails - Import SQL file as seed
View seeds.rb
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 Apr 18, 2018
Last exercise of the Read and Eval Chapter of Brave Clojre
View infix.clj
(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 Apr 5, 2018
Function composition and piping (or chaining) using reduce
View compose.py
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 Mar 19, 2018 — forked from craigvantonder/flush-dns.sh
Flushing the DNS in Ubuntu 16.04
View flush-dns.sh
#!/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 Mar 16, 2018
Chapter 3 excercise for the "Clojure for the Brave and True" -- For hitting hobbits
View smash_hobbits.clj
(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}
You can’t perform that action at this time.