Skip to content

Instantly share code, notes, and snippets.

@kblake
kblake / 0_reuse_code.js
Created January 30, 2014 19:04
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
@kblake
kblake / movies.swift
Created June 14, 2014 17:19
What if... Swinatra
get ("/movies") {
return Movie.all
}
get ("/movies/:id") {
movie = Movie.get(params["id"])
return movie
}
2014-09-30 21:01:01.432+0000 INFO [o.n.s.CommunityNeoServer]: Setting startup timeout to: 120000ms based on -1
2014-09-30 21:01:01.507+0000 INFO [o.n.k.InternalAbstractGraphDatabase]: No locking implementation specified, defaulting to 'community'
2014-09-30 21:01:01.557+0000 INFO [o.n.k.i.DiagnosticsManager]: --- INITIALIZED diagnostics START ---
2014-09-30 21:01:01.558+0000 INFO [o.n.k.i.DiagnosticsManager]: Neo4j Kernel properties:
2014-09-30 21:01:01.559+0000 INFO [o.n.k.i.DiagnosticsManager]: neostore.propertystore.db.mapped_memory=1285M
2014-09-30 21:01:01.559+0000 INFO [o.n.k.i.DiagnosticsManager]: neostore.nodestore.db.mapped_memory=357M
2014-09-30 21:01:01.559+0000 INFO [o.n.k.i.DiagnosticsManager]: neostore.relationshipstore.db.mapped_memory=1575M
2014-09-30 21:01:01.559+0000 INFO [o.n.k.i.DiagnosticsManager]: neostore.propertystore.db.strings.mapped_memory=1092M
2014-09-30 21:01:01.559+0000 INFO [o.n.k.i.DiagnosticsManager]: store_dir=/Users/karmenblake/Downloads/neo4j-community-2.1.5/data/
@kblake
kblake / fizzbuzz
Created December 2, 2014 23:51
Fizz Buzz in Elixir
defmodule FizzBuzz do
def compute(n) do
s = case {rem(n, 3), rem(n, 5)} do
{0, 0} -> :FizzBuzz
{0, _} -> :Fizz
{_, 0} -> :Buzz
_ -> n
end
IO.puts(s)
end
@kblake
kblake / gist:a99bf6b3c549780e7523
Created January 30, 2015 03:06
Cell server - Conway's Game of Life
IO.puts "Conway's Game of Life"
defmodule Cell do
def next_cycle do
receive do
{sender, number_live_neighbors} ->
cond do
number_live_neighbors < 2 ->
send sender, {:died, die_off}
number_live_neighbors > 3 ->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="jquery-1.3.min.js" type="text/javascript"></script>
</head>
<body>
FireUnit Fun!
<input type="text" id="blah" name="blah" value="blah" /><br/>
<div id="some_div">some div</div>
</body>
</html>
#Examples:
# modalbox_spawn(:link_text=>"content", :content=>"Content for light box", :width=>1000)
# modalbox_spawn(:link_text=>"partial render", :partial=>"partials/education_component", :locals=>{:key=>"value"})
# modalbox_spawn(:link_image=>"icons/pedigree_button1.gif", :content=>"<h2>COMING SOON: Pedigree Viewer. w00t!</h2>")
# modalbox_spawn(:link_text=>"View Pedigree", :classes=>"black_link other1 other2", :content=>"<h2>COMING SOON: Pedigree Viewer. w00t!</h2>")
# modalbox_spawn(:link_text=>"View Pedigree", :id=> person_being_viewed, :content=>"some content")
def modalbox_spawn(options={})
link_path = options[:link_path] || root_path
link_display = options[:link_text] || image_tag(options[:link_image])
##########################################
#Ruby idioms
########################################
#old school
breakfast = nil
if !breakfast
breakfast = "bacon"
end
#cool but is there a better way?
breakfast = "bacon" unless breakfast
#todo use select
def self.getDnaLab(lab_name)
DnaLabs.each do |lab|
if lab.name == lab_name
return lab
end
end
return nil
end
#todo: use select
def self.getDnaLab(lab_name)
DnaLabs.detect{|lab| lab.name == lab_name}
end
def self.getLabDisplayName(labName)
getDnaLab(labName).try(:display_name) || ""
end