Skip to content

Instantly share code, notes, and snippets.

@hello-josh
hello-josh / remove-whitespace.md
Last active April 23, 2024 20:37
How to remove whitespace changes from a branch for a PR

How to remove whitespace-only changes from a PR

  1. Create a new local branch that will contain your changes without the whitespace

    git checkout -b tmp-branch

  2. Merge the changes that contain whitespace into your current branch WITHOUT committing the changes

    git merge --no-commit

@hello-josh
hello-josh / cvf.json
Created June 10, 2020 20:35
Continuous Verification Framework JSON example
{
"name": "Continuous Verification Framework",
"type": "json"
}
@hello-josh
hello-josh / crawler.go
Last active December 6, 2019 01:54
A Tour of Go - Exercise: Web Crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@hello-josh
hello-josh / deferred_flask.py
Created March 10, 2016 14:27
Deferred task using Flask's request context
@login_manager.user_loader
def load_user(user_id):
user = models.User.get_by_id(user_id)
if user and not user.timezone:
lat_long = request.headers.get('X-Appengine-Citylatlong', None)
deferred.defer(set_user_timezone, user_id, lat_long)
return user
def set_user_timezone(user_id, lat_long):
@hello-josh
hello-josh / index_action.php
Last active November 9, 2015 17:10
Functional replacement for App\Action\IndexAction from http://www.sitepoint.com/build-nasa-photo-gallery-zend-expressive/
<?php
function index_action(TemplateRendererInterface $templateRenderer) {
return function (ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null) use ($templateRenderer) {
$html = templateRenderer->render('app::index');
$response->getBody()->write($html);
return $response->withHeader('Content-Type', 'text/html');
}
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
struct node *prev;
struct node *next;
int info;
} Node_t;
void display(Node_t *start);
class Switch(object):
"""The INVOKER class"""
@classmethod
def execute(cls, command):
command.execute()
class Command(object):
"""The COMMAND interface"""
def __init__(self, obj):
self._obj = obj
<?php
/**
* Simple Command Pattern Class
*/
class MyCommand {
private $arg1;
private $arg2;
public function __construct($arg1, $arg2) {
$this->arg1 = $arg1;
$this->arg2 = $arg2;
@hello-josh
hello-josh / command-pattern.php
Created August 20, 2015 19:01
Command Pattern implementation using Anonymous functions instead of objects
<?php
/**
* Lamp object to be manipulated because a Lamp is a thing
*/
class Lamp {
public function turn_on() {
echo 'The light is on' . PHP_EOL;
}
public function turn_off() {
echo 'the light is off' . PHP_EOL;
@hello-josh
hello-josh / getter_sort.php
Last active August 29, 2015 14:27
An alternative idea to the <=> T_SPACESHIP from https://wiki.php.net/rfc/combined-comparison-operator
<?php
/**
* User Getter Sort - Sorts an array using a user defined getter function.
*
* An imaginary user defined sort alternative where you pass a function that
* returns the data that should be used to determine sort order
* @param array &$array Array to sort in place
* @param Callable $itemfunc The callable that receives the array
* item and returns the value that should