Skip to content

Instantly share code, notes, and snippets.

View cesartalves's full-sized avatar

César Alves cesartalves

View GitHub Profile
Concatenating filters: "deck:name" "is:new" "-is:suspended" //- == !
@cesartalves
cesartalves / new_app.py
Created October 8, 2019 18:06 — forked from ianschenck/new_app.py
Run your flask app under twisted wsgi, ALWAYS.
if __name__ == "__main__":
reactor_args = {}
def run_twisted_wsgi():
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource
resource = WSGIResource(reactor, reactor.getThreadPool(), app)
site = Site(resource)
@cesartalves
cesartalves / uninstall_gems.sh
Created November 28, 2019 21:28 — forked from IanVaughan/uninstall_gems.sh
Uninstall all rbenv gems
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
@cesartalves
cesartalves / install-sonar-scanner.sh
Created January 22, 2020 18:44
Install sonar-scanner on server
#!/bin/bash
# run as sudo to have access to /opt or change the directory
# check docks for additional info
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
curl -o /opt/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873-linux.zip
cd /opt/
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
@cesartalves
cesartalves / StatePatternExample.php
Last active March 15, 2020 15:57
Real world State pattern example php
<?php
class Order {
public function sendToEcommerce(){
switch($this->status){
case 'created':
$params["access_token"] = "### Chave de Acesso ###";
$data["Order"]["status_id"] = $this->status_id;
@cesartalves
cesartalves / StrategyPattern.php
Created March 15, 2020 16:10
Strategy Pattern real world example
<?php
class Product1 {
public function sendToMarketplace(){
if ($this->marketplace == 'Amazon') {
//huge code block
} elseif ($this->marketplace == 'Via Varejo') {
//huge code block
} elseif ($this->marketplace == 'Magalu') {
@cesartalves
cesartalves / crontab
Created April 8, 2020 13:20
health-check-crontab
# * * * * * DISPLAY=:0 /usr/bin/zenity --info --text="stretch" --title="reminder"
# * * * * * /bin/echo "cron works" >> /tmp/file
# * * * * * /usr/bin/zenity --notification --text="stretch" --title="reminder" --display=:0.0
# this one on top doesn't work unless we do as below
DISPLAY=:0.0
# * * * * * eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; /usr/bin/notify-send "TEST" "Crons work!"
40 * * * * eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; /usr/bin/notify-send "REMINDER" "Check posture!"
30 10,14,17 * * * eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; /usr/bin/notify-send "REMINDER" "Take a break! (stretch, coffee, etc)"
@cesartalves
cesartalves / Dockerfile
Last active May 26, 2020 18:10
Sidekiq image (crontab + whenever)
FROM ruby:2.5.7
RUN apt-get update && apt-get install -y cron
RUN apt-get install -y nano
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
ENV BUNDLE_PATH /gems
class NilObjectUnderstadingStrategy
def self.can_talk_to?(character)
true
end
end
class HumanCharacterUnderstandingStrategy
def self.can_talk_to?(character)
character.is_a? Human
end