Skip to content

Instantly share code, notes, and snippets.

View tahb's full-sized avatar

Tom Hipkin tahb

  • dxw
  • London
View GitHub Profile
@tahb
tahb / Transposition Decrypter
Created July 9, 2013 23:17
Transposition Decrypter
def transposition_decrypter(key)
# Calculate the length of columns based on the message length and how many letters in this key attempt
col_length = (@encrypted_message.length) / key
answer = []
group_count = 0
groups = {}
# Create character groups for each column + 1 so we start at 1 for readability
@tahb
tahb / colour_dither
Created July 19, 2013 13:53
Colour Dither
public ColorImage apply(ColorImage image)
{
// Store the image objects width and height in local variables.
int image_width = image.getWidth();
int image_height = image.getHeight();
// Store all given fixed colours into array.
Color[] palette = new Color[8];
palette[0] = new Color (0,0,0);
palette[1] = new Color (255,255,255);
@tahb
tahb / tippers
Created July 29, 2013 13:23
Example logic for tipping application
package com.example.tippers;
import java.math.BigDecimal;
import java.text.NumberFormat;
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
@tahb
tahb / hash.rb
Last active August 29, 2015 13:57
Hash Merge
# Remove duplicate keys
array = [ Hash[ burger: 1], Hash[burger: 2, pie: 1] ]
array.reduce({}) do |result, department|
result.merge(department) do |key, left, right|
left + right
end
end
# {:burger=>3, :pie=>1}
# Override the right hash with the left
@tahb
tahb / Ruby Array
Last active August 29, 2015 13:57
Array set operations
lunch_list = %W[beer bread bananas]
dinner_list = %W[beer steak chips]
# Combining arrays whilst preserving uniqueness
lunch_list | dinner_list == (lunch_list + dinner_list).uniq
=> ["beer", "bread", "bananas", "steak", "chips"]
# Adding to an array whilst preserving uniqueness
lunch_list |= [ "cake" ]
@tahb
tahb / Add lib files to load path
Last active August 29, 2015 14:00
in config/application.rb
Dir.glob( Rails.root.join("lib", "ext", "*.rb") ).each { |f| require f }
or
config.autoload_paths << Rails.root.join('lib')
@tahb
tahb / gist:a428dfc90491e70821c4
Created July 2, 2014 14:06
Iterating over and modifying hashes inside an array
hash = Hash[key: "value1", key: "value2"]
hash2 = Hash[key: "value1", anotherkey: "value2"]
array = [hash, hash2]
array.each { |hash| hash.inject({}) { |h, (k,v)| h[k] = "blue"; h} }
@tahb
tahb / worm_game.rb
Created January 22, 2015 14:23
Ruby worm game (found on a forum)
#!/usr/bin/env ruby
require 'gosu' # gem install gosu --no-document
include Gosu
$dimension, $splits = 200, 20
$size = $dimension.to_f / $splits.to_f
class Worm
attr_writer :dir
def initialize() reset end
@tahb
tahb / fingerprint.rb
Created May 18, 2015 14:29
Fingerprint for Certificate with OpenSSL
cert = OpenSSL::X509::Certificate.new(x)
fingerprint = OpenSSL::Digest::SHA1.new(cert.to_der).to_s
puts fingerprint.scan(/.{2}/).join(":").upcase
@tahb
tahb / README.md
Created August 20, 2015 20:52
CS:GO Config 2015-08

C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg\config.cfg


unbindall
bind "0" "slot10"
bind "1" "slot1"
bind "2" "slot2"
bind "3" "slot3"
bind "4" "slot4"