Skip to content

Instantly share code, notes, and snippets.

Avatar
🐵
Echando rostro en Ixtapa.

Manuel Montoya aarkerio

🐵
Echando rostro en Ixtapa.
View GitHub Profile
@aarkerio
aarkerio / support_request_spec.rb
Last active May 3, 2021
Rails rspec shopify login
View support_request_spec.rb
def shopify_login(shop)
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:shopify, provider: 'shopify', uid: shop.myshopify_domain,
credentials: { token: shop.api_token })
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:shopify]
get "/auth/shopify/callback?shop=#{shop.myshopify_domain}"
follow_redirect!
@aarkerio
aarkerio / shop_request_spec.rb
Last active Oct 27, 2020
Shopify request test
View shop_request_spec.rb
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'ShopsController', type: :request do
def login(shop)
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:shopify, provider: 'shopify', uid: shop.myshopify_domain,
credentials: { token: shop.api_token })
Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:shopify]
@aarkerio
aarkerio / graphql.rb
Created Aug 25, 2020
Shopify GraphQL API. Search products and its variants
View graphql.rb
query = %{ { products(first: 20, query: "title:*bik*")
{ edges { node { id
title
priceRange { maxVariantPrice { amount } minVariantPrice { amount } }
featuredImage { transformedSrc altText }
variants(first:10) { edges { node { id title price } } } } } } } }
url = 'https://dev-store-rdigital.myshopify.com/admin/api/2020-07/graphql.json'
def api_headers
@aarkerio
aarkerio / profiles.clj
Last active May 11, 2020
Connect cider with Luminus (May/2020)
View profiles.clj
I tried following the Cider docs but I was getting the message:
Wrong number of arguments: (4 . 4), 0
Error from syntax checker clojure-cider-eastwood: Done with no errors
Anyhow I could fix it, the next should work:
;; My file in $HOME/.lein/profiles.clj.
{:user {
:dependencies [
View number_ocurrences.clj
;; In a new hotel containing 100 rooms, Tom was hired to paint the numbers from 1-100 on the doors.
;; How many times will Tom have to paint the number 8?
(get (frequencies (clojure.string/join (range 101))) \8)
@aarkerio
aarkerio / core.cljs
Created Apr 10, 2020
ClojureScript: Hidde flash message after 4 seconds
View core.cljs
(defn ^:export flash-timeout []
(when-let [flash-msg (gdom/getElement "flash-msg")]
(js/setTimeout #(set! (.-className %) "css-hidden-class") 4000 flash-msg)))
@aarkerio
aarkerio / libs.clj
Created Feb 7, 2020
Clojure. Update some keys in a map.
View libs.clj
(defn str-to-int
"Convert some string keys in a map to integer"
[coll & int-keys]
(let [listed (set int-keys)]
(reduce-kv #(assoc %1 %2 (if (contains? listed %2 ) (Integer/parseInt %3) %3)) {} coll)))
(str-to-int {:qt "56" :kl "Some String" :wer "22" :jj "This is ok" :aa "456" :ll "Address"} :aa :qt :wer)
;; => {:qt 56, :kl "Some String", :wer 22, :jj "This is ok", :aa 456, :ll "Address"}
@aarkerio
aarkerio / clj-odf.clj
Created Jan 28, 2020
Create a LibreOffice text ODF file
View clj-odf.clj
(ns clj-odf.core
(:import java.net.URI
org.odftoolkit.simple.TextDocument
org.odftoolkit.simple.table.Cell
org.odftoolkit.simple.table.Table
org.odftoolkit.simple.text.list.List))
(defn generate-odf [filename]
(let [outputOdt (TextDocument/newTextDocument)
uri (URI. "/home/manuel/Documents/lisplogo_fancy_256.png")
@aarkerio
aarkerio / posts.clj
Created Jan 22, 2020
Clojure. Format an Instant
View posts.clj
(:require [java-time :as jt]))
(defn format-date
"Format a Java instant"
[date]
(let [formatter (jt/format "dd-MM-yyyy HH:mm")]
(jt/format formatter (.atZone date (jt/zone-id)))))
;; clj-time is now deprecated
@aarkerio
aarkerio / anagram.rb
Created Jan 20, 2020
Remove duplicated anagrams from Array
View anagram.rb
class Anagram
def initialize
@unique_anagrams = nil
end
def my_array
@unique_anagrams ||= ["perro", "algo", "qwer","uuu", "lujo", "peorr","lago","edfr", "sadasd", "uljo", "erpro", "perro", "jolu"]
end