Skip to content

Instantly share code, notes, and snippets.

View pepesenaris's full-sized avatar

Jose Javier Señaris pepesenaris

View GitHub Profile
on:
- pull_request
jobs:
trigger-ci:
runs-on: ubuntu-latest
steps:
- name: CircleCI Trigger on Pull Request
id: gh_action_pull_request
uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.2
with:
@pepesenaris
pepesenaris / github-api-graphql-stale-branches.rb
Last active November 6, 2020 20:53 — forked from defeated/github-api-graphql-stale-branches.rb
GitHub API GraphQL - list stale branches
require 'graphlient'
client = Graphlient::Client.new('https://api.github.com/graphql',
headers: {
'Authorization' => "Bearer #{ ENV['GITHUB_API_TOKEN']}"
},
http_options: {
read_timeout: 20,
write_timeout: 30
}
@pepesenaris
pepesenaris / with_mailer_route.js
Created July 19, 2018 18:23
Send email route handler
// server/index.js
const mailer = require("./mailer"); // In the top of the file
/* ... */
app.get("/api/send_email", function(req, res) {
res.set("Content-Type", "application/json");
const locals = { userName: req.body.userName };
const messageInfo = {
@pepesenaris
pepesenaris / mailer.js
Last active July 19, 2018 20:36
Express mailer
//server/mailer.js
var path = require("path");
var templatesDir = path.resolve(__dirname, "views/mailer");
var Email = require("email-templates");
const mailjet = require("node-mailjet").connect(
process.env.MJ_APIKEY_PUBLIC,
process.env.MJ_APIKEY_PRIVATE
);
{
"scripts": {
"start": "node server",
"heroku-postbuild": "cd react-ui/ && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
}
}
@pepesenaris
pepesenaris / initial_setup_express.js
Created July 19, 2018 18:03
Express boilerplate to send email
// server/index.js
app.use(express.json()); /* Parse json in request */
/* Priority serve any static files */
app.use(express.static(path.resolve(__dirname, "../react-ui/build")));
app.get("/api/send_email", function(req, res) {
res.set("Content-Type", "application/json");
@pepesenaris
pepesenaris / assestment.md
Last active July 7, 2018 19:54
Thinkful assestment

JavaScript

This is a good example of the fact that most of our Javascript code is not executed in the moment is "read" by the browser rather than at some point later in time, usually as a callback triggered by a browser event or user interaction.

The problem here is that each loop interation defines a new function but each function share the same scope. Let's consider scope as the set of variables that are accesible from a piece of code, for example the function body in this case.

Given how Javacript works we are able to use the btnNum variable that was declared in an outer scope, ie outside the function. The tricky part is that each function points to the same btnNum variable and when those functions are executed, the btnName always holds the same value. In this case the value is 3, which is not a valid offset for the array of prizes, so we obtain undefined as a price.

The key here is to remember that functions in Javascript define a new scope and we can treat functions as any other primitive va

@pepesenaris
pepesenaris / gist:72b3e20d0645341f02a8
Last active March 17, 2016 03:28
Rails temp zip response example
#helper method to generate temp zip file
def generate_temp_zip_file(base_name, items)
tmpfile = Tempfile.new([base_name, '.zip'], 'tmp')
Zip::ZipOutputStream.open(tmpfile) {|zop|} #Necessary to create empty zip
Zip::ZipFile.open(tmpfile.path, Zip::ZipFile::CREATE) do |zip_file|
items.each do |entry|
zip_file.add(entry[:name], entry[:src_path])
end
end