Skip to content

Instantly share code, notes, and snippets.

View gabidavila's full-sized avatar
💁‍♀️
I try to solve all my problems with a single SQL query.

Gabriela Ferrara gabidavila

💁‍♀️
I try to solve all my problems with a single SQL query.
View GitHub Profile
2.4.1 :001 > user = User.first
User Load (0.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> #<User id: 1, name: "Gabriela", created_at: "2018-02-06 14:25:06", updated_at: "2018-02-06 14:25:06">
2.4.1 :002 > Address.create(street: "111 8th Ave", city: "New York", state: "NY", user: user)
(0.2ms) BEGIN
SQL (1.9ms) INSERT INTO "addresses" ("street", "city", "state", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["street", "111 8th Ave"], ["city", "New York"], ["state", "NY"], ["user_id", 1], ["created_at", "2018-02-06 14:28:51.050940"], ["updated_at", "2018-02-06 14:28:51.050940"]]
(5.7ms) COMMIT
=> #<Address id: 1, street: "111 8th Ave", city: "New York", state: "NY", zipcode: nil, user_id: 1, created_at: "2018-02-06 14:28:51", updated_at: "2018-02-06 14:28:51">
2.4.1 :003 > user
=> #<User id: 1, name: "Gabriela", created_at: "2018-02-06 14:25:06", updated_at: "2018-02-06 14:25:06">

Keybase proof

I hereby claim:

  • I am gabidavila on github.
  • I am gabidavila (https://keybase.io/gabidavila) on keybase.
  • I have a public key whose fingerprint is 9656 6392 F402 856F A447 B80B 2B8E F14E CC27 3FD3

To claim this, I am signing this object:

@gabidavila
gabidavila / division_by_zero.md
Last active December 13, 2017 14:51
MySQL Bug Report for division by zero

MySQL 5.7 doesn't support division by 0 in write operations. However in virtual columns they are allowed, but if you try to update a row that previously had division by zero to another value so not to cause the division by zero you get an error and the row gets immutable.

Create a table trips as the following:

CREATE TABLE trips (
  id         INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  start_time DATETIME         NOT NULL,
  end_time   DATETIME         NOT NULL,
  distance   INT(10)          NOT NULL DEFAULT 0,
function reverseString(word) {
const new_word = [];
const array_chars = word.split("");
const last_index = array_chars.length - 1;
for (let i = 0; i <= Math.ceil(array_chars.length/2); i++) {
new_word[last_index - i] = array_chars[i];
new_word[i] = array_chars[last_index - i]
}
WITH RECURSIVE fibonacci(recursion_level, fibonacci_number, next_number)
AS (
# Base Case
SELECT 0 AS recursion_level,
0 AS fibonacci_number,
1 AS next_number
UNION ALL
# Recursion query
SELECT recursion_level + 1 AS recursion_level,
next_number AS fibonacci_number,
@gabidavila
gabidavila / _introduction.md
Last active April 11, 2019 17:32
Determines if a positive integer is a palindrome mathematically

Using Math to find palindromes

For an instance, forget that arrays and strings exists. Your challenge, is to say if a number is a palindrome or not using mostly mathematical approach.

The string you will receive (because it is an user input), it always positive. You can assume that every 0 &lt;= n &lt; 10 is a palindrome.

React USA Map: A package for customizing the USA map without D3

TL;DR;

  • I created a React package called react-usa-map
  • It displays the USA map with the states including DC / Hawaii / Alaska
  • It's MIT license
  • Install instructions on The Package section of this post.

Package origins

Application Problem

Sort the characters in the following string:

abcdefghijklmnopqrstuvwxyz_

by the number of times the character appears in the following text (descending):

Note: the text scrolls.

@gabidavila
gabidavila / Test
Created September 8, 2017 17:57
Testing API
aaaa
@gabidavila
gabidavila / Test
Created September 8, 2017 17:56
Testing API
aaaaa