Skip to content

Instantly share code, notes, and snippets.

require 'test_helper'
class AccountControllerTest < ActionController::TestCase
context 'GET to edit for existing account' do
setup do
@account = Factory(:account)
Account.stubs(:find).returns(@account)
get :edit, :id => @account.to_param
end
@ktec
ktec / gist:467980
Created July 8, 2010 13:13 — forked from vlado/formtastic_mark_it_up_editor.rb
added markitup viewhelpers and force output to a string
module FormtasticExtensions
module Formtastic
module MarkItUpEditor
include MarkItUp::ViewHelpers
def self.included(base)
base.class_eval do
@mark_it_up_dependencies_included = false
end
end
@ktec
ktec / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ktec
ktec / sum_of_primes.hs
Created December 31, 2015 22:28
Sieve of Eratosthenes in Haskell
import Data.List
import qualified Data.Map as Map
import System.Environment (getArgs)
-- credit The Genuine Sieve of Eratosthenes (Melissa E. O’Neill)
sieve xs = sieve' xs Map.empty
sieve' [] table = []
sieve' (x:xs) table =
case Map.lookup x table of
defmodule Day1 do
defp _position(str) do
str
|> Stream.unfold(&String.next_codepoint/1)
|> Stream.map(&do_decode/1)
|> Stream.with_index
|> Stream.transform(0, &do_floor/2)
|> Stream.map(&IO.inspect(&1))
|> Enum.to_list
|> List.last

Keybase proof

I hereby claim:

  • I am ktec on github.
  • I am globalkeith (https://keybase.io/globalkeith) on keybase.
  • I have a public key whose fingerprint is 9E55 DA5C 53D6 288F 667B 04D3 420A 1F32 D5B5 C752

To claim this, I am signing this object:

@ktec
ktec / prime_factorizer.rb
Last active November 1, 2016 11:01
A class which generates the prime factors for a given number. It tries to do it in a relatively optimised way by using a lazy prime generator inside an enumerator.
class Prime
def self.primes
isComposite = -> (n) {(3..Math.sqrt(n)).step(2).any?{ |i| n % i == 0 }}
Enumerator.new do |e|
e.yield 2 # start at 2
(3..Float::INFINITY) # start generator from 3
.step(2) # sieve all even numbers
.lazy # calculate on demand
.reject(&isComposite) # sieve all composites numbers
.map(&:to_i) # reduce to ints
Whenever you push to remote that has "production" in its name,
this hook will show commits and changes and then ask for confirmation.
Copy or symlink to:
.git/hooks/pre-push.
Make the file executable:
chmod +x .git/hooks/pre-push
@ktec
ktec / arel_cast_datetime_as_as.rb
Last active June 27, 2016 14:39
When you want to filter by date, but you've only got a datetime property, this will help you cast your datetime
# frozen_string_literal: true
class Things < ApplicationRecord
scope :filter_after_date, -> (date) {
where(created_at_as_date.gteq(date))
}
scope :filter_before_date, -> (date) {
where(created_at_as_date.lteq(date))
}
def self.created_at_as_date
Arel::Nodes::NamedFunction.new "DATE", [ arel_table[:created_at] ]