Skip to content

Instantly share code, notes, and snippets.

View nisevi's full-sized avatar
🧑‍🚀
Working from anywhere

Nicolas Sebastian Vidal nisevi

🧑‍🚀
Working from anywhere
View GitHub Profile
@nisevi
nisevi / citrusbyte.rb
Last active January 2, 2017 16:32
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
# a = [[1,2,[3]],4]
# aux = []
def flatten(a, aux)
a.each do |n|
if n.instance_of?(Fixnum)
aux<<n
elsif n.instance_of?(Array)
flatten(n, aux)
end
end
@nisevi
nisevi / ApiTestTrait.php
Last active March 13, 2017 22:52
How to check the keys of a JSON in PHP?
<?php
namespace Tests\Traits;
trait ApiTestTrait
{
public function assertApiResponse(Array $actualData)
{
$this->assertApiSuccess();
@nisevi
nisevi / s3_public_read
Last active October 6, 2017 23:18
Granting Read-Only Permission to an Anonymous User - http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::examplebucket/*"]
}
@nisevi
nisevi / config.yml
Last active January 24, 2024 04:27
CircleCI 2.0 deploy to S3 static website - configuration file.
version: 2
jobs:
build:
working_directory: /tmp/vasko
docker:
- image: circleci/python:3.6.2-stretch-browsers
steps:
- checkout
- run:
name: Deploying Vasko.
@nisevi
nisevi / markdown_converter.rb
Created April 13, 2018 21:18
This service acts as a wrapper that encapsulates the 'kramdown' functionality.
class MarkdownConverter
attr_reader :markdown
private :markdown
def initialize(markdown)
@markdown = markdown
end
def as_html
converted_markdown.html_safe
@nisevi
nisevi / github_static_pages_job.rb
Last active April 15, 2018 09:41
Module that holds the logic for pulling and saving to database the '.md' files that live in the root path of a GitHub repository.
require 'octokit'
require 'base64'
module GithubStaticPagesJob
extend self
FILE_NAME_REGEX = /\w+[^\.md]/
def client
credentials = {
@nisevi
nisevi / static_pages_controller.rb
Last active April 14, 2018 10:19
Action rendering the static content.
def show
return false if redirect_email_blunder
@page = StaticPage.friendly.find(get_page_id(params[:id]))
@ancestry = @page.self_and_ancestors.map(&:title).reverse
end
@nisevi
nisevi / show.html.erb
Created April 14, 2018 10:20
Code in the view for displaying the content of the static page.
<div id="static_page_body"><%= clean_html(@page.body) %></div>
@nisevi
nisevi / github_content_for_static_pages.rake
Last active April 15, 2018 09:42
Rake task for calling the logic that resides within GithubStaticPagesJob module.
namespace :fetch_github do
desc 'Get github content for static pages'
task :content_for_static_pages => :environment do
GithubStaticPagesJob.run
end
end
@nisevi
nisevi / primes_table
Created April 24, 2018 13:55
File where command line options are handled.
#!/usr/bin/env ruby
require 'optparse'
require 'methadone'
require 'primes_table.rb'
class App
include Methadone::Main
include Methadone::CLILogging