Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
@mikecmpbll
mikecmpbll / totp
Last active October 29, 2015 14:23 — forked from jurisgalang/totp
Ruby implementation of the Time-Based One-Time Password (TOTP) Algorithm described at http://tools.ietf.org/html/rfc6238
[jgalang@rashomon:~/Code/skunkworks/2fa]
∴ ruby totp_demo.rb
Time(sec) Time (UTC format) Value of T(Hex) TOTP Mode OK
------------------------------------------------------------------------------------------
59 1970-01-01 00:00:59 0000000000000001 94287082 SHA1 ✔
59 1970-01-01 00:00:59 0000000000000001 46119246 SHA256 ✔
59 1970-01-01 00:00:59 0000000000000001 90693936 SHA512 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 07081804 SHA1 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 68084774 SHA256 ✔
@mikecmpbll
mikecmpbll / _form.html.haml
Created October 27, 2015 16:45
trying to embed erb inside yml locale file
.form-actions
- if params[:action] == "new"
= button_tag type: "submit", class: "btn btn-success btn-cons",
id: "submit" do
= fa_icon "check"
%span  Create
= link_to courses_path, class: "btn btn-danger btn-cons" do
= fa_icon "close"
%span  Cancel
print "Enter an integer number to be calculated as factorial: "
Integer(gets) rescue print "Hey, that's not an integer! Enter an integer, please: "
n = gets.to_i
def factorial n
n > 1 ? n * factorial(n - 1) : 1
end
puts "Factorial of number #{n} is #{factorial(n)}"
@mikecmpbll
mikecmpbll / code
Last active August 29, 2015 14:18 — forked from baditaflorin/code
#!/usr/bin/env ruby
# encoding: utf-8
require 'savon'
require 'csv'
startDate = Date.new(2004, 01, 01)
stopDate = Date.today
csvHeaders = ['numar', 'numar_vechi', 'data', 'institutie', 'departament',
'categorie_caz', 'stadiu_procesual', 'obiect', 'data_modificare','nume','calitate_parte','solutie']
@mikecmpbll
mikecmpbll / console
Last active August 29, 2015 14:04 — forked from anonymous/console
1.9.3p392 :002 > Postcode
=> Postcode(id: integer, postcode: string, long: decimal, lat: decimal, address: string, bias: string, data: text, tries: integer, updated_at: datetime, created_at: datetime)
1.9.3p392 :003 >
AppUser.authenticate('ADMIN', '')
AppUser Load (0.9ms) EXEC sp_executesql N'SELECT TOP (1) [AppUsers].* FROM [AppUsers] WHERE [AppUsers].[UserID] = N''ADMIN'' AND [AppUsers].[Password] = N'''' ORDER BY [AppUsers].[UserID] ASC'
=> #<AppUser UserID: "ADMIN", UserName: "Administrator", MenuGroup: "SYS_ADMIN", Password: "", DefaultStoreID: "1", FullRights: true, LastChanged: "2013-10-23 17:59:52", ChangedBy: "ADMIN", Email: "", Phone: "", Deleted: false, CashierID: "", HideCostPrice: false, WebLogin: false, CustomerID: "", DepID: "", NetworkID: "">
@mikecmpbll
mikecmpbll / example.rb
Last active August 29, 2015 14:04 — forked from anonymous/example.rb
search_all = LOCAL_SETTINGS["single_site_search"]
if params[:ref].present?
spaces = Space.where(id: { params[:ref] }, parent_id: nil })
spaces = spaces.eager_loads(slots: :companies).where(companies: { parent_id: current_company_id }) unless search_all
render partial: 'call_centre_results' and return
end
@mikecmpbll
mikecmpbll / en.yml
Created June 26, 2014 14:00 — forked from smaboshe/en.yml
# Variable substitution works here
foo: "The quick brown %{ animal } jumped over the lazy dog"
# Variable substitution done not work here
# Instead, "%{ animal }" gets rendered
bar: "The quick
brown %{ animal }
jumped over
the lazy dog"
class JTask
# JTask.find()
# Retrieves records from the database file.
# --------------------------------------------------------------------------------
# Eg: JTask.find("test.json", 1) || JTask.find("test.json", first: 10)
# #=> <JTask id=x, ...>
# --------------------------------------------------------------------------------
# See wiki guide for more usage examples...
# https://github.com/adammcarthur/jtask/wiki/find
class Widget < ActiveRecord::Base
attr_accessible :name, :snippets, :snippets_attributes, :company_id, :hostname, :first_page, :affiliate_id, :item_defaults, :read_only
has_many :snippets
has_many :permissions, dependent: :destroy
has_many :users, through: :permissions
accepts_nested_attributes_for :snippets
attr_accessor :read_only
def read_only
true