Skip to content

Instantly share code, notes, and snippets.

View aarkerio's full-sized avatar
🐵
Echando rostro en Ixtapa.

Manuel Montoya aarkerio

🐵
Echando rostro en Ixtapa.
View GitHub Profile
users = User.all
newall = users.map do |u|
u.attributes[:new_field] = Time.now
end
#
# I need to know if one product in the purchased "order_list" has an 'Event' product_type
# The models: order_list table belongs_to order_items and order_items belongs_to products
#
def has_event?(order_list)
order_list.order_items.each do |oi|
oi.product.each do |product|
return true if product.product_type == 'Event'
end
end
@aarkerio
aarkerio / appointments.jsx
Created October 21, 2015 21:23
React SyntaxError: unknown: Unexpected token
render: function() {
var trNodes = this.props.data.map(function (appointment) {
return (
<tr><td>{appointment.id}</td><td>{appointment.scheduled_time}</td><td>{appointment.pet_id}</td><td>Delete</td></tr>
);
});
var commentNodes = return (
<div className="commentBox">trNodes</div>
);
(:require [goog.dom :as gdom]
[goog.style :as style])
(defn my-toggle [element-str]
(let [div-message (gdom/getElement element-str)]
(style/showElement div-message (not (style/isElementShown div-message)))))
@aarkerio
aarkerio / ClojureScript Ajax POST
Last active August 27, 2018 21:10
ClojureScript Ajax POST
(defn set-message [response]
(.log js/console (str ">>> RESPONSE #####" response)))
(defn error-handler [response]
(.log js/console (str ">>> RESPONSE #####" response)))
(defn save-json []
(let [json (.-value (gdom/getElement "json-field"))
id (.-value (gdom/getElement "upload-id"))
csrf-field (.-value (gdom/getElement "__anti-forgery-token"))]
@aarkerio
aarkerio / gist:5b9676f2b935fbea796581dc51db643a
Created August 31, 2018 20:48
Clojure: change value in map from string to boolean
(def answer {:answer "France" :correct "true" :age 11})
(update answer :correct #(if (= % "true") true false))
@aarkerio
aarkerio / edit_area.cljs
Last active October 22, 2018 19:17
Hide show ClojureScript reagent edit form
(defn question-item
[{:keys [question explanation hint key qtype id ordnen] :as q}]
(let [counter (reagent/atom 0)
editing (reagent/atom false)] ;; show and switch icons (Edit/Cancel)
(fn []
[:div.div-separator {:key (str "div-question-separator-" id) :id (str "div-question-separator-" id)}
(if @editing
[:img.img-float-right {:title "Cancel question"
:alt "Cancel question"
:key (str "cancel-question-img-" id)
@aarkerio
aarkerio / Encode & decode strings Ruby
Last active November 7, 2018 19:55
Encode & decode strings Ruby
class RunLengthEncoding
def self.encode(input)
new_array = split_by_chars input
ordered = new_array.map do |el|
el.length > 1 ? "#{el.length}#{el.chr}" : el
end.join
end
def self.decode(input)
@aarkerio
aarkerio / Curl upload file graphql
Created February 18, 2019 03:22
Curl upload file graphql Apollo lambda
curl localhost:3000/graphql \
-F operations='{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { filename } }" }' \
-F map='{ "0": ["variables.file"] }' -F 0=@/home/mmontoya/Bilder/mydog12.jpg
yarn add -D git+ssh://git@github.com:aarkerio/graphql-api-types.git