Skip to content

Instantly share code, notes, and snippets.

@rob-murray
rob-murray / find-max-count-from-list.java
Created January 8, 2013 20:27
Find the maximum count value of list of integers in Java
public class TestApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Try with list of set values
List<Integer> listSet = new ArrayList<Integer>();
listSet.add(1);
@rob-murray
rob-murray / set_agv_ver.sh
Last active July 1, 2022 01:31
Use agvtool to set Xcode project build number
#!/bin/bash
#
# Use agvtool to set Xcode project build number and create git tag
# Note: requires Xcode project configured to use Apple Generic Versioning and git
#
# Usage: set_agv_ver.sh 123
#
# src: https://gist.github.com/rob-murray/8644974
#
@rob-murray
rob-murray / blog_post.rb
Last active April 15, 2022 14:52
Rails STI form components conditional by type
# app/models/blog_post.rb
class BlogPost < Post
has_many :comments
end
@rob-murray
rob-murray / gen_http_cont_md5.rb
Last active January 7, 2022 20:00
Generate a base64 encoded md5 hash of a file in Ruby for use in http Content-MD5 header
require 'digest'
def main
raise ArgumentError, 'Please specify a file to work with' unless ARGV.length == 1
file_path = ARGV[0]
digest = Digest::MD5.base64digest(File.read( file_path ))
puts "The MD5 digest base64 encoded MD5 is #{digest} of file #{file_path}."
@rob-murray
rob-murray / console_out.rb
Created January 9, 2015 08:55
Update a Rails readonly field
2.1.5 :020 > User
=> User(id: integer, name: string, email: string, created_at: datetime, updated_at: datetime)
2.1.5 :021 > User.create(name: 'rob', email: 'orb@example.com')
(0.1ms) begin transaction
SQL (1.0ms) INSERT INTO "users" ("name", "email", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "rob"], ["email", "orb@example.com"], ["created_at", "2015-01-09 08:50:31.962223"], ["updated_at", "2015-01-09 08:50:31.962223"]]
(0.8ms) commit transaction
=> #<User id: 2, name: "rob", email: "orb@example.com", created_at: "2015-01-09 08:50:31", updated_at: "2015-01-09 08:50:31">
2.1.5 :022 > User.first
User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 2, name: "rob", email: "orb@example.com", created_at: "2015-01-09 08:50:31", updated_at: "2015-01-09 08:50:31">
@rob-murray
rob-murray / commands.txt
Last active November 24, 2020 10:36
Testing Google Play In App Billing receipt validation.Commands to generate signature digest from receipt using private key; also validate signature using public key
#1 Generate Public & Private Keypair
#2 Create receipt.json - eg below - careful with line-endings, etc if line breaks
#3 Create signature & Encode
openssl dgst -binary -sha1 -sign private.pem receipt.json | openssl base64 > signature.txt
#4 Verify using OpenSSL & public key
openssl base64 -d -in signature.txt -out signature.sha1 | openssl dgst -sha1 -verify public.pem -signature signature.sha1 receipt.json
# frozen_string_literal: true
# rubocop:disable
def puts_here(symbol: "*")
puts symbol + caller(1..1).first + symbol * 50
if block_given?
yield
puts symbol + caller(1..1).first + symbol * 50
end
end
@rob-murray
rob-murray / mysql-bk.sh
Created January 8, 2013 21:27
A(nother) MySql database backup shell script
!bin/sh
#####################################
### Backup script - run_backup.sh ##
#####################################
### Desc: Runs backup on MYSQL ##
### database and then emails to ##
### confirm ##
#####################################
# Settings
@rob-murray
rob-murray / PDOConnection.php
Last active March 11, 2020 11:14
An class for a PHP PDO connection - a singleton implementation. An instance method returns a new PDO Connection with the specified connection attributes.
<?php
namespace ACompany\AnAppName\Dao\PdoImpl;
/**
* PDOConnection is a singleton implementation.
* getConnection() returning an instance of PDO connection.
*
* <code>
* Example usage:
rails new app_name \
--database=postgresql \
--skip-action-cable --skip-action-mailer --skip-active-storage \
--skip-sprockets --skip-action-mailbox --skip-action-text \
--skip-bundle --skip-keeps --skip-spring --skip-test \
--skip-coffee --skip-system-test --skip-turbolinks