Skip to content

Instantly share code, notes, and snippets.

View thomasbiddle's full-sized avatar

TJ (Thomas J.) Biddle thomasbiddle

View GitHub Profile
@thomasbiddle
thomasbiddle / Create-Administrator.ps1
Last active December 28, 2017 23:42 — forked from ducas/Create-Administrator.ps1
Create a local administrator account using PowerShell
$Username = "su"
# Likely needs a capital letter, certain length and a number.
$Password = "TempPassword1"
$group = "Administrators"
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
@thomasbiddle
thomasbiddle / cancan-grape.rb
Created November 14, 2014 17:12
CanCan helper for a Grape API implementation
def authorize!(role={}, object)
ability = Ability.new(current_user)
unless ability.can?(role, object)
unauthorized!
end
end
@thomasbiddle
thomasbiddle / revoke-from-security-group
Created December 24, 2013 00:50
This will revoke your current IP address to the security group of choice. Assumes EC2 tools are on your PATH.
#!/bin/bash
# Initialize our own variables:
GROUP="default"
REGION="ap-northeast-1"
# Get our real public IP.
IP_ADDRESS=`curl ifconfig.me --silent`
@thomasbiddle
thomasbiddle / add-to-security-group
Created December 24, 2013 00:49
This will add your current IP address to the security group of choice. Assumes EC2 tools are on your PATH.
#!/bin/bash
# Initialize our own variables:
GROUP="default"
REGION="ap-northeast-1"
# Get our real public IP.
IP_ADDRESS=`curl ifconfig.me --silent`
def artists(query)
results = search('artist', query)
artists = []
results['artists'].each do |artist|
artists << Resources::Artist.new(artist)
end
Resources::Base.new(results['info'], artists)
end
require 'sinatra'
require 'net/http'
get '/' do
is_up = Net::HTTP.start('play.noobonicplague.com').head('/')
code = is_up.code
if code == '200'
"It's up!"
else
...
rescue Trac::TracException
@retries_trac ||= 0
@retries_trac += 1
@logger.info("Trac isn't responding - Retry ##{@retries_trac}.")
retry if @retries_trac < 10
....
@thomasbiddle
thomasbiddle / gist:6142764
Created August 2, 2013 19:35
Retry an rescued block
def my_test
puts 'test1'
begin
puts 'test2'
raise Exception, 'Oh noes!'
rescue Exception
retry
end
Started POST "/users/sign_in" for 192.168.28.1 at 2013-07-11 13:39:35 -0700
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xodISf4lGqUE6JBs3plknQwFfkTF1MZwIMk8MBhAuGQ=", "user"=>{"username"=>"tjbiddle", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."username" = 'tjbiddle' LIMIT 1
Completed 401 Unauthorized in 128ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xodISf4lGqUE6JBs3plknQwFfkTF1MZwIMk8MBhAuGQ=", "user"=>{"username"=>"tjbiddle", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/shared/_links.erb (0.8ms)
Rendered devise/sessions/new.html.erb within layouts/application (46.6ms)
Completed 200 OK in 259ms (Views: 249.4ms | ActiveRecord: 0.0ms)
# Using friendly IDs to translate the name in the route to the ID.
project_name = params[:id].to_s
if Project.where('name like ?', project_name).empty?
@project = Project.new
@project.name = project_name
notify("info", "Project does not exist - Create one!")
return render :action => 'new'
else
@project = Project.where('name like ?', project_name).first