Skip to content

Instantly share code, notes, and snippets.

View toddnestor's full-sized avatar

Todd D Nestor toddnestor

View GitHub Profile
require 'net/ssh'
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: ruby permission.rb [-h some-host-option -a lock -u garion]"
%i{host user action}.each do |option|
opts.on("-#{option[0]}VALUE", "--#{option}=VALUE") do |value|
@toddnestor
toddnestor / template_method_arguments.rb
Created May 3, 2017 22:20
class for extracting arguments from a string
# This class is solely used for extracting arguments from a string
# It is used to process the arguments input to template_methods in the CMS content areas
# It handles arguments that are comma separated, inside or outside of quotes
# Like normal arguments to a programming function if something is inside a quote it will
# all be part of the same argument and commas inside of quotes are part of that argument
# rather than used to separate it from another argument. It also takes into account backslashes
# so 'I\'m an argument' will properly be processed
#
# For example link("http://google.com", 'Google is fun to use, really it is')
# It will result in the arguments:
<?php
function forceDownload()
{
$file_name = "/some/directory/not/publicly/available/" . $_GET['file'];
$file = file_get_contents( $file_name );
if( !empty($file) )
{
-module(numbers).
-export([fib/1, triangle_numbers/1, triangle_number/1, bsearch/2, pair_sum/2]).
fib(1)->
[0];
fib(2)->
[0,1];
fib(N)->
PrevFibs = fib(N-1),
lists:append(PrevFibs, [ lists:nth(length(PrevFibs) - 1, PrevFibs) + lists:last(PrevFibs) ] ).
@toddnestor
toddnestor / erlang-fibonacci.erl
Created December 7, 2016 07:58
Fibonaccie sequence in erlang
-module(fibonacci).
-export([process/1]).
process(1) ->
[0];
process(2) ->
[0,1];
process(N) ->
lists:append(process(N - 1), [ lists:last(process(N - 1)) + lists:last(process(N - 2) ) ] ).
@toddnestor
toddnestor / pig_latinize.rb
Last active July 28, 2016 23:16
Another ruby Pig Latin translator
def translate( words )
words.translate
end
class String
def grab_punctuation
punctuation = ''
if !self[-1].match(/[a-z]/i)
punctuation = self[-1]
def pig_latinize_word( word )
parts = word.split(/\b([^a,e,i,o,u]{0,}qu|[^a,e,i,o,u]+)?([a,e,i,o,u][a-z]{0,})?/i) #https://regex101.com/r/yP8yF9/3 <-- this is where I worked out the regex
parts.shift if parts.first.empty? #getting rid of that first empty element that results from the regex matching the entire word, adding the conditional just in case there are outliers where the first word is not blank that I haven't thought of
parts << parts.shift #moving the first element to be the last element
"#{parts.join('')}ay"
end
def translate( words )
( words.split(' ').inject([]) {|pig_latinized_words,word| pig_latinized_words << pig_latinize_word( word )} ).join(' ') #did it all in one line because I was curious if Ruby would let me, it just splits the words up by spaces, makes a new array of the pig latinized words, and then joins them back with spaces
end
@toddnestor
toddnestor / angular cart sample
Last active March 14, 2016 21:03
Angular cart sample for Ed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-app="app" ng-controller="myAppController">
<h3>Items</h3>
<ul>
@toddnestor
toddnestor / cart.html
Last active March 14, 2016 21:02
Simple jQuery cart for Ed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h3>Items</h3>
<ul class="display_items"></ul>
<hr>
<h2>Original: </h2>
<div id="original">http://0e24f87c32490a111f93f3579380e24d7f3579f.0e24f87c32490a1117f3579380e24f87c32490a111a3d7f3579f.0e24f87c32490a111f.0e24f87c32490a111f937ffffa3.0e24f82490af111f9f373d7f3579380e24f87c2490a111f937a3d7f3579f.tdneffsdsafstor.sometdhing.smarffffftmefsmbffff.com.uk/whaffdffffffffffffffffffsadffdsarg+whatev?he=that http://google.com/somewhere toddnestor.com yourmom.com google.com http://google.com somewhere.so whatever.sow.u whatever.sow.uk wow.wo https:something.com https://something.com //solid.online <img src="http://google.com" /> toddnestor.com, toddnestor.com. toddnestor.com: toddnestor.com? toddnestor.com!</div>
<h2>Linkified: </h2>
<div id="linkified"></div>
<script>
var linkify = function( string ) {
var re = /(?:^|\ )(((?:(?:http(?:s)?\:)?(?:\/\/))|(?:\/\/))?(?:(?=[a-z0-9\-\.]{1,255}(?=\/|\ |$|\:|\?|\,|\!))(?:(?:(?:[a-z0-9]{1}(?:[a-z0-9\-]{1,62})?\.){1,127})[a-z]{2,}(?:\.[a-z]{2})?))(?:[a-z0-9\/\-\_\%\?\&\!\$\'\,\(\)\*\+\=\;])*?)(?=$|\.(?=\ |$)|\:|\ |\?(?=\ |$)