Skip to content

Instantly share code, notes, and snippets.

View thehenster's full-sized avatar

Henry thehenster

  • https://char.gy
  • London
View GitHub Profile
# As root user
sudo su
# Update the OS
apt-get update -y
# Setup Hostname & TimeZone
echo "{{HOSTNAME}}" > /etc/hostname
hostname -F /etc/hostname
@thehenster
thehenster / netcat-listen-on-port.sh
Last active December 8, 2015 14:40
The nc in Ubuntu doesn't have the same arguments as the normal one
# in normal nc
nc -l -p 8888
# in bsd nc
nc -l 0.0.0.0 8888
# throw in a -k to keep listening to subsequent requests
@thehenster
thehenster / scripttag.html
Last active November 17, 2015 09:10
script tag in gist
<script>alert('hello');</script>
@thehenster
thehenster / recipe_form.rb
Last active November 16, 2015 16:18
Pattern for Form Objects in Rails
class RecipeForm
ATTRIBUTES = [:name, :cooking_time_minutes]
attr_reader :recipe
attr_accessor *ATTRIBUTES
def initialize(recipe)
@recipe = recipe
end
@thehenster
thehenster / to_string
Created October 26, 2012 09:08
to_string
########
# Author: Henry Turner
# Project: to_string
# Description: A speedy algorithm to convert a string to a string
# License: MIT
########
def to_string
# process the string
 self.to_s
end
@thehenster
thehenster / capybara-cheatsheet.rb
Created March 6, 2015 11:14
Capybara Cheatsheet
# A Capybara Cheatsheet
# In rails 3
Post.select(:id, :created_at).count #=> SELECT COUNT(*) FROM posts
# In rails 4
Post.select(:id, :created_at).count #=> SELECT COUNT(id, created_at) FROM posts ... bang
Post.select(:id, :created_at).count(:all) #=> SELECT COUNT(*) FROM posts
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord'
#!/usr/bin/env ruby
# Give me two arguments.
# 1) the path of the pwsafe xml file to import
# 2) the path of the csv to export
# format of lastpass data
# url,username,password,extra,name,grouping,fav
require 'nokogiri'
@thehenster
thehenster / gist:183c3efefa6343895452
Created May 19, 2014 16:18
Delegation of class methods through an association..
class Event < ActiveRecord::Base
has_many :artists
end
class Artist < ActiveRecord::Base
def self.make_me_an_artist
create! do |artist|