Skip to content

Instantly share code, notes, and snippets.

View galileoguzman's full-sized avatar
🤓
Making the world programmable

Galileo Guzmán galileoguzman

🤓
Making the world programmable
View GitHub Profile
@galileoguzman
galileoguzman / break.py
Created January 13, 2023 18:17 — forked from obfusk/break.py
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use https://docs.python.org/3/library/pdb.html
import code; code.interact(local=dict(globals(), **locals()))
@galileoguzman
galileoguzman / pluggable.php
Created February 11, 2021 22:14 — forked from ethicalhack3r/pluggable.php
WordPress authentication cookie generation using default keys
<?php
if ( !function_exists('wp_generate_auth_cookie') ) :
/**
* Generate authentication cookie contents.
*
* @since 2.5.0
*
* @param int $user_id User ID
* @param int $expiration Cookie expiration in seconds
@galileoguzman
galileoguzman / how-to-upgrade-heroku-postgresql.md
Created March 17, 2020 00:39 — forked from simonw/how-to-upgrade-heroku-postgresql.md
How to upgrade a Heroku PostgreSQL database to a new plan

How to upgrade a Heroku PostgreSQL database to a new plan

I started a project on a Hobby Dev plan (free, limit 10,000 rows), and then later needed to upgrade it to Hobby Basic ($9/month, limit 10,000,000 rows).

After assigning the new database, I had two databases attached to the application. They looked something like this:

  • HEROKU_POSTGRESQL_OLIVE (postgresql-dimensional-3321) Old, free-tier (Hobby Dev) database
# importing python libraries
from datetime import datetime, time, timedelta
from functools import reduce
# defining the scope of tasks in time daily
START_TIME = datetime.now().replace(hour=6, minute=0, second=0, microsecond=0)
LIMIT_TIME = datetime.now().replace(hour=7, minute=0, second=0, microsecond=0)
TIME_AWAIT = 15
def is_time_between(begin_time, end_time, check_time=None):
@galileoguzman
galileoguzman / Phone.swift
Created July 4, 2018 23:34
Format phone number for each UITextField on a ViewController
// https://stackoverflow.com/questions/1246439/uitextfield-for-phone-number/13227608#13227608
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
{
var fullString = textField.text ?? ""
fullString.append(string)
if range.length == 1 {
textField.text = format(phoneNumber: fullString, shouldRemoveLastDigit: true)
} else {
textField.text = format(phoneNumber: fullString)

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@galileoguzman
galileoguzman / storingEmailsInFile.php
Created February 9, 2018 19:03
For little problems fix 'em with little solutions. We were in a project where we just had apache and php installed and we needed save emails from a form with ajax.
<?php
function saveEmail($email){
$file = 'emails.txt';
return file_put_contents($file, PHP_EOL.$email, FILE_APPEND | LOCK_EX);
}
function validateEmail($email) {
import statistics as stats
numbers_mean = [1525, 257, 378, 9543, 7854, 152]
numbers_mode = [9, 5, 9, 4, 3, 6, 7, 1, 2, 3, 9, 1, 2]
numbers_median = [9, 5, 9, 4, 3, 6, 7, 1, 2, 3, 9, 1, 2]
print("Mean: " + stats.mean(numbersMean))
print("Mode: " + stats.mode(numbersMode))
@galileoguzman
galileoguzman / models.py
Last active November 8, 2017 08:26
Make view for search inside Django web app with a query string and return template with pagination options.
from __future__ import unicode_literals
from django.db import models
from autoslug import AutoSlugField
from ckeditor.fields import RichTextField
from django.template.defaultfilters import slugify
class Post(models.Model):
title = models.CharField(max_length=75)
body = RichTextField('body')
@galileoguzman
galileoguzman / app.js
Created August 14, 2017 17:46 — forked from RickWong/app.js
React without Webpack
const App = ({name}) => {
return (
<h1>Hello {name}</h1>
);
};
ReactDOM.render(<App name="World" />, document.getElementById("App"));