Skip to content

Instantly share code, notes, and snippets.

@smoak
smoak / output
Created September 25, 2014 17:40
Trying to create a test case for missing a slash when dealing with engines.
$ ruby test_case_missing_slash.rb
Run options: --seed 62773
# Running:
D, [2014-09-25T10:40:05.782387 #7511] DEBUG -- :
D, [2014-09-25T10:40:05.782441 #7511] DEBUG -- :
I, [2014-09-25T10:40:05.782843 #7511] INFO -- : Started GET "/test" for 127.0.0.1 at 2014-09-25 10:40:05 -0700
F, [2014-09-25T10:40:05.783768 #7511] FATAL -- :
RuntimeError (Could not find root path for #<TestEngine1::Engine:0x007f3beee14110>):
@smoak
smoak / _form.html.erb
Created November 13, 2014 22:53
Rails select form helper with has_many through
<%= form_for(@patient) do |f| %>
<% if @patient.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@patient.errors.count, "error") %> prohibited this patient from being saved:</h2>
<ul>
<% @patient.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
ruby_block "create services" do
block do
service_res = Chef::Resource::Service.new service_name, run_context
service_res.provider Chef::Provider::Service::Upstart
service_res.supports status: true, restart: true, reload: true
service_res.subscribes :restart, "deploy_revision[#{service_name}]", :delayed
service_res.run_action :enable
end
action :run
end
@smoak
smoak / TilesGame.java
Created August 4, 2015 06:35
TiledGame trying to get it to work
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.tiled.TiledMap;
var myObject = {
property1: 'test',
myFunc: function(arg) {
// the 'this' object refers to the instance of the myObject variable
this.property1 = arg;
alert("Does this === myObject ? " + (this === myObject ? "yes" : "no") );
var a = function() {
// inside a closure the 'this' object is now === window
alert("Does this === window ? " + (this === window ? "yes" : "no"));
@smoak
smoak / TwistedStuff.py
Created May 18, 2011 00:38
Twisted Stuff
from twisted.internet import reactor, defer
class Api:
def __init__(self):
self.domainObjects = None
self.subscribers = []
def test(self, url):
# code for doing the async stuff here
@smoak
smoak / json
Created July 22, 2011 23:20
ASP.NET MVC 3 JSON
/*
Assuming you have JSON POSTed to your action in the form:
{ "id": 1, "name": "John Smith", "description": "Some description here" }
*/
// class for the POSTed data
[Serializable]
public class SomeJsonModelFormData
@smoak
smoak / gist:1189418
Created September 2, 2011 18:33 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
Day job:
Software Developer by day...and night
Favorite Python project:
Twisted
Favorite Conference:
Haven't been to any *sad trombone*
Python Experience Level:
@smoak
smoak / gist:1204901
Created September 8, 2011 22:04
HtmlHelper to get Controller name
public static class HtmlHelperExtensions
{
public static string ControllerName<TController>(this HtmlHelper helper) where TController : Controller
{
return typeof(TController).Name.Replace("Controller", string.Empty);
}
}
var orders = new [] { 1, 5, 7, 42 };
var customers = new [] { 1, 2, 3, 4, 5, 6, 7, 42 };
var customersWithOrdersCount = 0;
foreach (var c in customers) {
foreach (var o in orders) {
if (c == o) {
customersWithOrdersCount++;