Skip to content

Instantly share code, notes, and snippets.

View Lewiscowles1986's full-sized avatar
🤓

Lewis Cowles Lewiscowles1986

🤓
View GitHub Profile
@Lewiscowles1986
Lewiscowles1986 / scalar-pad.js
Last active November 7, 2015 11:55
JavaScript Padding numbers & strings
"use strict";
String.prototype.pad = function( len, c, left ) {
var s = '',
c = ( c || ' ' ),
len = Math.max( len, 0 ) - this.length,
left = ( left || false );
while( s.length < len ) { s += c };
return ( left ? ( s + this ) : ( this + s ) );
}
Number.prototype.pad = function( len, c, left ) {
@Lewiscowles1986
Lewiscowles1986 / rPiJessie4GB-p1.sh
Last active November 7, 2015 16:14
Resizing 8GB Jessie rPi image to 4GB
#!/bin/bash
# Root Check
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Get rid of Wolfram
sudo apt-get purge wolfram-engine
@Lewiscowles1986
Lewiscowles1986 / provision-hospitalrun.sh
Created November 11, 2015 22:27
HospitalRun.io vagrant test env
#!/bin/bash
# Install NodeJS via NVM
sudo apt-get install -y git-core curl
curl https://raw.githubusercontent.com/creationix/nvm/v0.3.0/install.sh | bash
echo "source /home/vagrant/.nvm/nvm.sh" >> /home/vagrant/.profile
source /home/vagrant/.profile
nvm install 0.12
nvm alias default 0.12
@Lewiscowles1986
Lewiscowles1986 / Vagrantfile
Last active November 22, 2015 20:38
Drupal 8 Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "debian/jessie64"
config.vm.network "private_network", ip: "10.0.0.48"
config.vm.hostname = "drupal8.local"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
@Lewiscowles1986
Lewiscowles1986 / magic.js
Created December 17, 2015 17:44
better sorting for imgur galleries
// Drop this directly into the console
jQuery('.sortable-image img, .sortable-image').css({width:'auto',height:'auto'})
jQuery('.sortable-image img').each( function(e,elem) {
var fixedImg = jQuery(this).attr('src').replace('s.png','.png');
jQuery(this).attr( 'src', fixedImg );
});
@Lewiscowles1986
Lewiscowles1986 / weird.js
Created December 28, 2015 17:56
Weird Palindrome
/*
* so I decided to check out freecodecamp today, just to see how it was
*
* It's okay, but I have to question the value of learning to write a palindrome checker, that to my mind is not much use...
* Here was my punt at it (it passed, I just don't love the look of it)
*/
function palindrome(str) {
// Good luck!
str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
@Lewiscowles1986
Lewiscowles1986 / src\ReadingTime.php
Last active December 29, 2015 06:29
PHP Estimated Read Time
<?php
namespace lewiscowles\utils\cms;
class ReadingTime {
protected static function _read_time( $text, $wordsPerPage = 200.00, $decimalPlaces = 2 )
{
$words = str_word_count( strip_tags( $text ) );
$min = floatval( $words ) / $wordsPerPage;
@Lewiscowles1986
Lewiscowles1986 / utils.offsets.in.func.php
Created January 5, 2016 15:39
find all offsets in a string
<?php
function offsetsIn(string $haystack, string $needle, $cs=true) : array {
$offset = false;
$pos = 0;
$out = [];
$func = $cs ? '\strpos' : '\stripos';
while (strlen($haystack) > 0 && ($pos === 0 || $offset !== false)) {
if($offset !== false) {
$out[] = $offset;
@Lewiscowles1986
Lewiscowles1986 / setup.sh
Created June 29, 2016 21:15
Alphagov calculators deploy...
#!/bin/bash
sudo apt-get update
sudo apt-get remove --purge ruby -y
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
export PATH="$PATH:$HOME/.rvm/bin"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash
export NVM_DIR="/home/vagrant/.nvm"
@Lewiscowles1986
Lewiscowles1986 / Vagrantfile
Last active July 21, 2016 19:16
Debian / Ubuntu get ruby on rails
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.31.17"
config.vm.hostname = "rails.demo"
config.vm.provider "virtualbox" do |vb|