Skip to content

Instantly share code, notes, and snippets.

<?php
function register()
{
if (!empty($_POST)) {
$msg = '';
if ($_POST['user_name']) {
if ($_POST['user_password_new']) {
if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
if (strlen($_POST['user_password_new']) > 5) {
if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
@robmiller
robmiller / gist:7562495
Created November 20, 2013 12:38
Ruby one-liner for transposing rows to columns
echo "foo\nbar\nbaz\nfoo\nbar\nbaz" | ruby -pe 'BEGIN{i=0}; $_.chomp! << "\t" unless (i += 1) % 3 == 0'
# Input:
#
# foo
# bar
# baz
# foo
# bar
# baz
** Invoke spec (first_time)
** Invoke vendor_orgmode (first_time)
** Invoke /Users/rob/src/quarto/vendor/org/lisp (first_time, not_needed)
** Invoke vendor/org-8.0.7 (first_time, not_needed)
** Invoke vendor/org-8.0.7.tar.gz (first_time, not_needed)
** Invoke vendor (first_time, not_needed)
** Execute vendor_orgmode
** Execute spec
/Users/rob/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S rspec ./spec/quarto/build_spec.rb ./spec/quarto/pandoc_epub_spec.rb ./spec/tasks/codex_spec.rb ./spec/tasks/export_spec.rb ./spec/tasks/highlight_spec.rb ./spec/tasks/master_spec.rb ./spec/tasks/sections_spec.rb ./spec/tasks/skeleton_spec.rb -t ~org
Run options: exclude {:org=>true}
ruby -e 'p ",\x05\x14\x14\x1DD&\r\x16\x10\f\x00\x05\x1DD#\x11\x1D".chars.map{|x|(x.unpack("C")[0]^100).chr}.join'
@robmiller
robmiller / .vimrc
Last active January 2, 2016 20:29
Match Chris Coyier's "words to avoid in tech writing", adapted from @pengwynn's original
highlight TechWordsToAvoid ctermbg=red ctermfg=white
function MatchTechWordsToAvoid()
match TechWordsToAvoid /\c\<\(obviously\|basically\|simply\|of\scourse\|clearly\|just\|everyone\sknows\|however\|so,\|easy\)\>/
endfunction
autocmd FileType markdown call MatchTechWordsToAvoid()
autocmd BufWinEnter *.md call MatchTechWordsToAvoid()
autocmd InsertEnter *.md call MatchTechWordsToAvoid()
autocmd InsertLeave *.md call MatchTechWordsToAvoid()
autocmd BufWinLeave *.md call clearmatches()
@robmiller
robmiller / gist:8651287
Created January 27, 2014 16:03
Prepend line to files in shell
# requires sponge, from joey hess's moreutils
# http://joeyh.name/code/moreutils/
for i in *.txt; do; echo "line to prepend\n" "$(cat $i)" | sponge $i; done
@robmiller
robmiller / sample-n.rb
Last active August 29, 2015 13:55
Select a random n values from an array that might have < n values
words = %w{foo bar baz}
n = 10
# If we use sample, we get a random order but never
# more than 3 entries:
words.sample(n)
# => ["bar", "foo", "baz"]
# A solution:
n.times.map { words.sample }
def method_a
method_b do |thing|
thing = 'hey'
end
end
def method_b
thing = nil
thing = yield thing
@robmiller
robmiller / av
Last active August 29, 2015 13:57
Take a webcam shot and save it in the pictures directory. Depends on tenderlove's av_capture: `gem install av_capture`
#!/usr/bin/env ruby
require 'av_capture'
require 'pathname'
session = AVCapture::Session.new
dev = AVCapture.devices.find(&:video?)
dir = Pathname(File.expand_path("~/Pictures/av"))
Dir.mkdir(dir) unless dir.exist?
@robmiller
robmiller / regex-o.rb
Last active March 3, 2017 03:14
Explaining Ruby regex's /o modifier
require "benchmark"
def letters
puts "letters() called"
sleep 0.5
"A-Za-z"
end
words = %w[the quick brown fox jumped over the lazy dog]