Skip to content

Instantly share code, notes, and snippets.

View alexanderjsingleton's full-sized avatar

Alex Singleton alexanderjsingleton

View GitHub Profile
@alexanderjsingleton
alexanderjsingleton / gist:a7e7cad8d04b62df3cb2
Last active August 29, 2015 17:43
regex for php conversion
Executed w/ Vim:
```
%s/src="\(img\/.\+\)"/<?php echo get_template_directory_uri(); ?>\/\1/g
%s/src="\(js\/.\+\)"/<?php echo get_template_directory_uri(); ?>\/\1/g
%s/href="\(css\/.\+\)"/<?php echo get_template_directory_uri(); ?>\/\1/g
```
@alexanderjsingleton
alexanderjsingleton / keybase.md
Created September 22, 2015 15:53
verification for keybase.io

Keybase proof

I hereby claim:

  • I am alexanderjsingleton on github.
  • I am alexjsingleton (https://keybase.io/alexjsingleton) on keybase.
  • I have a public key whose fingerprint is 6F14 7DB7 2CC6 E71B 8549 4155 8F99 C823 52A2 277E

To claim this, I am signing this object:

import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* Wombat. A Wombat moves forward until it hits the edge of the world, at
* which point it turns left. If a wombat finds a leaf, it eats it.
*
* @author Michael Kölling
* @version 2.0
*/
public class Wombat extends Actor
@alexanderjsingleton
alexanderjsingleton / gitPruner.sh
Last active October 8, 2015 17:02
For the derpy, albeit accidental, push to origin including your secrets.yml file...
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch config/secrets.yml' --prune-empty --tag-name-filter cat -- --all
@alexanderjsingleton
alexanderjsingleton / FizzBuzz_ExtendedCommentaryEdition.rb
Last active November 16, 2015 16:18
For my blog post describing optimal alogrithm design for performance-commentary included for n00bs :)
# *NOTE*, case statements are preferred over standard conditionals-this has been confirmed according to my very
# own academic research and engagements with CS professors-BUT-here is an outstanding explanation by [@DanielleSucher](http://www.daniellesucher.com/2013/07/ruby-case-versus-if/)
# define method 'fizzbuzz' initialized by single-variable argument 'number'
def fizzbuzz(number)
# define local method 'divisibleby3' defining a function checking divisibility of initialized by single-variable 'number' using the modulus and case-equality operators checking for remainder of 0 when divided by 3
divisibleBy3 = (number % 3 == 0)
# define local method 'divisibleby5' defining a function checking divisibility of initialized by single-variable 'number' using the modulus and case-equality operators checking for remainder of 0 when divided by 5
divisibleBy5 = (number % 5 == 0)
# construct case statement according to fizzbuzz specifications for 3 and 5, only 3 and only 5
case
@alexanderjsingleton
alexanderjsingleton / benchmark.rb
Last active December 16, 2015 18:52
An experiment supporting the most efficient fizzbuzz solution.
require 'benchmark'
def fizzbuzz(array)
array.map do |number|
divisibleBy3 = (number % 3 == 0)
divisibleBy5 = (number % 5 == 0)
case
when divisibleBy3 && divisibleBy5
puts "FizzBuzz"
@alexanderjsingleton
alexanderjsingleton / terminalOutput.txt
Created October 18, 2015 00:52
Benchmark test results for most efficient fizzbuzz solution.
Desktop ruby fizzbuzz.rb | grep 0.0
0.010000 0.000000 0.010000 ( 0.010018)
0.010000 0.000000 0.010000 ( 0.011353)
➜ Desktop ruby fizzbuzz.rb
fizzbuzz
== disasm: <RubyVM::InstructionSequence:fizzbuzz@fizzbuzz.rb>===========
== catch table
| catch type: break st: 0004 ed: 0008 sp: 0000 cont: 0008
|------------------------------------------------------------------------
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] array<Arg>
0000 trace 8 ( 3)
0002 trace 1 ( 4)
require 'benchmark'
N = Array(1..10_000_000)
def no_op(*a); end
def fizzbuzz(array)
array.each do |number|
divisibleBy3 = (number % 3 == 0)
divisibleBy5 = (number % 5 == 0)
@alexanderjsingleton
alexanderjsingleton / .htaccess.txt
Last active December 6, 2015 02:19
An example for redirecting WordPress instance via .htaccess (public_html/)
# Redirect traffic to https
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^[REDACTED]$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteOptions inherit
# BEGIN WordPress
<IfModule mod_rewrite.c>