Skip to content

Instantly share code, notes, and snippets.

View fabianhjr's full-sized avatar

Fabián Heredia Montiel fabianhjr

View GitHub Profile
@fabianhjr
fabianhjr / Gemfile
Last active August 29, 2015 14:04
Beautiful Omniauth Usage Example (Facebook/Github/etc)
# Things that must be added
gem 'devise'
gem 'omniauth-facebook'
gem 'omniauth-github'
@fabianhjr
fabianhjr / basechange.py
Created August 1, 2014 21:31
Change from [int] to [char:3][int:4] and back in Python
def func(num):
first = num % 10000
last = num / 10000
fmtString = ''
while last:
fmtString += str(unichr((last % 26) + 65))
last /= 26
return ("AAA" + fmtString[::-1])[-3:] + ("0000" + str(first))[-4:]
def invfunc(num):
parsed = int(num[-4:])
[{
"id": "1",
"district": "CUA",
"lon": "-99.168051",
"lat": "19.433296",
"bikes": "0",
"slots": "27",
"zip": "06500",
"address": "001 - R\u00edo Balsas-R\u00edo Sena",
"addressNumber": "S\/N",
x freq
1 295 5435
2 390 4419
3 398 3921
4 302 3748
5 305 3652
6 317 3430
7 340 3403
8 372 3392
9 291 3274
x freq
1 295 5279
2 390 4536
3 398 4135
4 302 3605
5 305 3543
6 291 3380
7 340 3177
8 372 3173
9 317 3108
** (exit) exited in: GenServer.call(#PID<0.148.0>, {:query, "CREATE TABLE IF NOT EXISTS \"schema_migrations\" (\"version\" bigint PRIMARY KEY, \"inserted_at\" timestamp)", []}, :infinity)
** (EXIT) an exception was raised:
** (UndefinedFunctionError) undefined function: Geo.PostGIS.Extension.init/2 (module Geo.PostGIS.Extension is not available)
Geo.PostGIS.Extension.init(%{"DateStyle" => "ISO, MDY", "IntervalStyle" => "postgres", "TimeZone" => "America/Monterrey", "application_name" => "", "client_encoding" => "UTF8", "integer_datetimes" => "on", "is_superuser" => "on", "server_encoding" => "UTF8", "server_version" => "9.4.4", "session_authorization" => "postgres", "standard_conforming_strings" => "on"}, [library: Geo])
(postgrex) lib/postgrex/types.ex:56: anonymous fn/2 in Postgrex.Types.prepare_extensions/2
(elixir) lib/enum.ex:909: anonymous fn/4 in Enum.into/3
(elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) li
def create(conn, %{"stress" => stress_params}) do
changeset = Stress.changeset(%Stress{}, stress_params)
IO.inspect stress_params
{long, lat, type} = {stress_params["long"], stress_params["lat"], stress_params["type"]}
q = from p in Plataforma.Average,
select: p,
where: p.long == ^long and p.lat == ^lat and p.type == ^type
average = Repo.all(q) |> first_or_create
average_params = %Plataforma.Average{"long" => stress_params["long"],
"lat" => stress_params["lat"],
@fabianhjr
fabianhjr / 1.py
Last active January 20, 2016 23:32
Platica
sum(range(100)) # -> 4950
from multiprocessing import Pool
def chunkify(lst, n):
return [lst[i::n] for i in range(n)]
# Ejemplo
partes = chunkify(range(100), 8)
# [range(0, 100, 8), range(1, 100, 8), range(2, 100, 8)...
@fabianhjr
fabianhjr / InterestingLanguages
Created July 20, 2016 01:02
Languages I find interesting
Java (Groovy, Scala, Clojure, Kotlin) ; The Javas
C (C++, D, Rust, Nim) ; System Programming
Python (Coconut) | Ruby | Crystal | Io | Smalltalk ; Multis/OOPs
JavaScript (Dart, Scala.js, Elm, ClojureScript, CoffeeScript) ; The Browser Languages
Assembly (x86, ARM, PowerPC, RISC-V) ; Assemblers
R | Sage ; Math
Perl | Lua ; Sysadmin/Scripting
Lisp (Scheme, Common Lisp, Emacs Lisp) ; Lisps
Prolog ; Logic Programming
Erlang (Elixir, LFE) | Go ; Concurrent/Distributed
@fabianhjr
fabianhjr / typing-missing
Created July 26, 2016 00:08
Home Assistant Typing
homeassistant/util/__init__.py:320: error: "module" has no attribute "PriorityQueue"
homeassistant/util/package.py:34: error: "module" has no attribute "SubprocessError"
homeassistant/util/package.py:59: error: Iterable expected
homeassistant/scripts/macos.py:17: error: Incompatible types in assignment (expression has type IO[Any], variable has type "TextIO")
homeassistant/helpers/event.py:88: error: Callable[..., Any] has no attribute "run"
homeassistant/loader.py:44: error: "module" has no attribute "__path__"
homeassistant/helpers/config_validation.py:353: error: Cannot determine type of 'CONDITION_SCHEMA'
homeassistant/helpers/config_validation.py:362: error: Cannot determine type of 'CONDITION_SCHEMA'
homeassistant/config.py:107: error: Cannot determine type of 'DEFAULT_CONFIG'
homeassistant/config.py:115: error: Cannot determine type of 'DEFAULT_CONFIG'