Skip to content

Instantly share code, notes, and snippets.

View bergpb's full-sized avatar
💻
https://blog.bergpb.dev

Lindemberg Barbosa bergpb

💻
https://blog.bergpb.dev
View GitHub Profile
@MariaCarolinass
MariaCarolinass / form.py
Last active October 26, 2020 18:49
tags n pra n
#!/usr/bin/env python -*- coding: utf-8 -*-
from flask import request
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, SelectField, TextField, TextAreaField, \
DateField, PasswordField, RadioField, BooleanField, SubmitField
from wtforms.validators import ValidationError, DataRequired, Length, \
Email, EqualTo, Regexp
from app.util.validators import Unique
from datetime import datetime
from flask_babel import _, lazy_gettext as _l
@onuralp
onuralp / Jenkinsfile
Last active January 6, 2021 17:43
Jenkins Shared lib function for VSTest Test Runner and Code Coverage Report
#!groovy
// I suggest you to add those functions as Shared Library https://jenkins.io/doc/book/pipeline/shared-libraries/
@Library('your-shared-lib') _
pipeline {
stages {
//..
stage('Run Unit Tests') {
steps {
@ChengLong
ChengLong / will_paginate in Sinatra.md
Last active January 9, 2021 00:09
Use will_paginate with ActiveRecord in Sinatra
  1. Add gem 'will_paginate', '~> 3.0' to Gemfile
  2. Add %w(will_paginate will_paginate/active_record).each {|lib| require lib} to config.ru
  3. Assuming modular Sinatra, open Sinatra::Base and add include WillPaginate::Sinatra::Helpers so that all views can use will_paginate
  4. In controller, @users = User.paginate(:page => params[:page], :per_page => 30)
  5. In view, = will_paginate @users will generate the pagers

If you want to style your pagers

  • Include this css in your layout
  • Style it
@brenopolanski
brenopolanski / npm-list-globally.md
Created November 1, 2016 19:34
Listing globally installed NPM packages and version
npm list -g --depth=0
@rcaneppele
rcaneppele / SessionTimeout.php
Created November 17, 2015 19:33
Configurando Session-Timeout no PHP
session_start();
$timeout = 600; // Tempo da sessao em segundos
// Verifica se existe o parametro timeout
if(isset($_SESSION['timeout'])) {
// Calcula o tempo que ja se passou desde a cricao da sessao
$duracao = time() - (int) $_SESSION['timeout'];
// Verifica se ja expirou o tempo da sessao
if($duracao > $timeout) {
@BaylorRae
BaylorRae / flash_messages.php
Created May 21, 2011 05:18
Flash Messages for PHP
<?php
class FlashMessages {
private $messages = array();
private $now = false;
private static $instance = null;
private function __construct() {
// Save all messages
$this->messages = $_SESSION['flash_messages'];
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#define EPD_CS SS
GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B73
#define BAT 35
@michels
michels / openweather_emoji.rb
Last active June 8, 2021 21:32
Uses the OpenWeatherMap to get an emoji based on the current weather // OpenWeaterMap emoji matcher in ruby.
OPENWEATHER_APIKEY = "" # TODO add your apikey here
lat = "49.868183" # latitude of the city you want to get the weather from
lon = "8.626288499" # longitude of the city you want to get the weather from
def getWeatherEmoji(weatherID)
# Openweathermap Weather codes and corressponding emojis
thunderstorm = "\u{1F4A8}" # Code: 200's, 900, 901, 902, 905
drizzle = "\u{1F4A7}" # Code: 300's
rain = "\u{02614}" # Code: 500's
@cmkoller
cmkoller / sinatra-flash.md
Last active July 25, 2021 07:34
Setting up Sinatra Flash

Setting Up Sinatra Flash

Sinatra Flash is an awesome gem that allows you to pop up little messages alerting your users of important things, via some simple code in your server.rb file. This is very useful for things like displaying error messages if the user has filled out a form wrong, or displaying "success" messages if the user did something successfully like sign in, sign out, or submit a form.

This also gives you a great chance to implement Foundation's beautiful alerts. Here's how to set it up!

  1. Install the gem by typing gem install sinatra-flash in your terminal.
  2. Require the gem in the top of your server.rb file: require 'sinatra/flash'