Skip to content

Instantly share code, notes, and snippets.

View Justintime50's full-sized avatar

Justin Hammond Justintime50

View GitHub Profile
@ammario
ammario / goth
Created September 2, 2016 16:27
golang test coverage html
#!/bin/bash
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
@coreywelch
coreywelch / LowercaseRoutes.php
Last active April 28, 2023 19:19
Here is a middleware class for laravel 5 that takes incoming routes and forces them to lowercase.
<?php
namespace App\Http\Middleware;
use Closure;
use \Illuminate\Support\Facades\Redirect;
class LowercaseRoutes
{
/**
@nickbclifford
nickbclifford / auto-deploying.md
Last active May 15, 2023 09:02
How to automatically deploy code to a server using Travis CI

Auto-Deploying via Travis CI

Because Travis CI can automatically execute scripts after successfully (or unsuccessfully!) executing tests, it is an obvious choice for a deployment tool. In order to deploy to a Git repository on a remote server, the process generally is as follows:

  • Set up SSH keys
  • Add the server's copy of the repository as a Git remote
  • Push to the remote
  • SSH into the server and execute any installation/compilation/miscellaneous commands

Before even touching .travis.yml...

Users

@wolph
wolph / update_wan_ip.rsc
Created March 25, 2017 16:37
Mikrotik script to detect WAN IP updates and call scripts if it changes.
:global wanInterface "wan1"
:global wanIP "$wanIP"
# Get the current IP on the interface
:local currentIPtemp [/ip address get [find interface="$wanInterface" disabled=no] address];
# IP without netmask
:local currentIP [:pick $currentIPtemp 0 ([:len $currentIPtemp]-3)];
:if ($currentIP != $wanIP) do={
@edthrn
edthrn / 1-Unit-testing with PyGithub.md
Last active October 19, 2023 05:09
Unit-testing with PyGithub

Intro

Lately, I've been building a Python platform that relies heavily on interactions with Github. Instead of re-inventing the wheel, I decided to go with PyGithub as a wrapper around Github v3 API.

The problem

This library implements the full API, which allows me to be very productive when I need to add a workflow in my platform that involves Github. However, it quickly became a real PITA to write unit tests. Even if the package comes with its own testing Framework, it is not documented yet and I didn't manage to crack it up in a decent amount of time.

I decided to hack the testing a little bit, using another very cool package, httpretty. Httpretty allows you to monkey patch the socket module during testing, so you can respond anything you want to any kind of network requests. Here's what I came up with, do not hesitate to give any feedback.


@evansde77
evansde77 / mock_requests.py
Last active January 31, 2024 08:49
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@arunoda
arunoda / gist:7790979
Last active February 16, 2024 14:05
Installing SSHPass

Installing SSHPASS

SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.

Installing on Ubuntu

apt-get install sshpass

Installing on OS X

@tmsnvd
tmsnvd / ruleset.md
Last active February 28, 2024 07:27
phpcs PHP_CodeSniffer rules list
Rule Namespace Description
Arrays.ArrayBracketSpacing /Squiz.Arrays.ArrayBracketSpacing Ensure that there are no spaces around square brackets.
Arrays.ArrayDeclaration /Squiz.Arrays.ArrayDeclaration Ensures that arrays conform to the array coding standard.
Arrays.DisallowLongArraySyntax /Generic.Arrays.DisallowLongArraySyntax Bans the use of the PHP long array syntax.
Arrays.DisallowShortArraySyntax /Generic.Arrays.DisallowShortArraySyntax Bans the use of the PHP short array syntax.
CSS.BrowserSpecificStyles /MySource.CSS.BrowserSpecificStyles Ensure that browser-specific styles are not used.
CSS.ClassDefinitionClosingBraceSpace /Squiz.CSS.ClassDefinitionClosingBraceSpace Ensure there is a single blank line after the closing brace of a class definition.
CSS.ClassDefinitionNameSpacing /Squiz.CSS.ClassDefinitionNameSpacing Ensure there are no blank lines between the names of classes/IDs.
CSS.ClassDefinitionOpeningBrace
@jwebcat
jwebcat / gist:5122366
Last active March 25, 2024 18:25 — forked from lemenkov/gist:1674929
Properly download from github using wget and curl
wget --no-check-certificate --content-disposition https://github.com/joyent/node/tarball/v0.7.1
# --no-check-cerftificate was necessary for me to have wget not puke about https
curl -LJO https://github.com/joyent/node/tarball/v0.7.1