Skip to content

Instantly share code, notes, and snippets.

View josiah14's full-sized avatar

Josiah josiah14

  • 47 Degrees
  • Remote
View GitHub Profile
@josiah14
josiah14 / reverse_string.rb
Last active August 29, 2015 14:20
reverse_string
def reverse_str(str)
str.split('').tap do |str_ary|
len = str_ary.length
(0..len / 2).each do
left = i
right = len - i - 1
str_ary[left], str_ary[right] = str_ary[right], str_ary[left]
end
str_ary.reduce(:+)
end
@josiah14
josiah14 / permutation.py
Created April 24, 2015 22:02
permutation_unordered_non-duplicate.py
def inverse_natural_sum(num, start):
for i in range(start, 0, -1):
num = num - i
if num == 0: return i
if num < 0: raise ValueError("number is not a natural sum.")
def permutations_unordered_no_repeat(collection):
def reducer(acc, x):
if acc == collection[0]:
return [ (acc, y) for y in collection[1:] ] + [ (x, y) for y in collection[2:] ]
@josiah14
josiah14 / new-leiningen.txt
Last active August 29, 2015 14:18
Create new Leiningen project
1. Use the official Leiningen documentation for installation. It is good enough to not warrant further documentation here.
2. Refer to https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md#tutorial for creating new projects. This documentation is also good enough.
@josiah14
josiah14 / typesafe-activator-install.md
Last active August 29, 2015 14:18
Install Typesafe Activator, Scala, SBT, etc.
  1. Download Typesafe activator from the main website (URL not provided because it may change and is easy to find on Google).

  2. mkdir ~/lib && mkdir ~/lib/activator

  3. cd ~/Downloads

    unzip typesafe-activator-1.3.2.zip -d ~/lib/activator

    mv ~/lib/activator/activator-1.3.2 ~/lib/activator/1.3.2

  4. echo 'export PATH=$PATH:~/lib/bin'

mkdir ~/lib/bin

@josiah14
josiah14 / new-maven.sh
Created April 7, 2015 23:25
Create new Maven projects
mvn archetype:generate -DgroupId=group.id -DartifactId=artifact-id -DarchetypeArtifactId=maven-archetype-quickstart
@josiah14
josiah14 / bummer.hs
Created November 23, 2014 07:35
Hmm. Haskell wont treat a (Functor f) => f String as a single value, so I can't make ((->) SomeType) into a Functor if the value returned by the Arrow is a Functor...
-- apply a style function to a shell prompt functor
-- e.g.
-- bold & fgColor red `style` gitCurrentBranch
style :: (String -> ShellPromptType -> String) -> ShellPromptSegment String
-> ShellPromptType -> ShellPromptSegment String
style f segment = \shType -> (flip f) shType <$> segment
-- this is fine
style' :: (String -> ShellPromptType -> String)
-> (ShellPromptType -> ShellPromptSegment String)
imageSignal : Signal Element
imageSignal = sampleOn (every second) (constant (image 400 400 imageURL))
fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
-- print the first 100 fibonacci numbers
main :: IO ()
main = print $ take 100 fibs
return otherCareManager.getId().equals(getId()) &&
otherCareManager.getCareManagerId().equals(getCareManagerId()) &&
otherCareManager.getClientId().equals(getClientId()) &&
otherCareManager.getName().equals(getName()) &&
otherCareManager.getVersion().equals(getVersion());
@josiah14
josiah14 / refactor.java
Created June 24, 2014 14:04
etl refactor
public class PersonnelETL extends BaseCommand {
@Override
protected final int run(CommandLine line) throws Exception {
return runETLProcess(
line,
ObjectGraph.create(
new PersonnelModule(
getConf(),
line.getOptionValue(OPTION_CLIENT),
line.getOptionValue(OPTION_POPULATION),