Skip to content

Instantly share code, notes, and snippets.

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 / 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

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:

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
@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
@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 / 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
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