Skip to content

Instantly share code, notes, and snippets.

View jeremywrowe's full-sized avatar
❤️
Coding

Jeremy W. Rowe jeremywrowe

❤️
Coding
View GitHub Profile
#include <stdio.h>
int main(int argc, char* argv[]) {
int a = 1;
a++;
printf("%d\n", a);
}
# => 2
render json: Resource.where(something: params[:something]).first_or_create do |r|
r.enabled = params[:enabled]
r.foo = params[:foo]
r.bar = params[:bar]
end
require "ostruct"
class Bar
attr_reader :num
def initialize(num)
@num = num
end
def zoo
@jeremywrowe
jeremywrowe / modules.rb
Created July 21, 2013 15:41
This is totally insecure and just a proof of concept. I find myself annoyed that parent modules have to exist prior to creating their children. Modules are a form of namespacing code and we should be able to organize that code however we want.
#!/usr/bin/env ruby
def create_module(representation, &block)
parts = representation.split("::")
(0...parts.size).each do |idx|
const = parts[(0..idx)].join("::")
eval "::#{const} = Module.new unless defined?(::#{const})"
end
if block_given?
@jeremywrowe
jeremywrowe / status_code.php
Last active December 20, 2015 15:19
This is an example of querying the chargify api and retrieving the status code of the response
<?php
$api_key = "";
$subdomain = "";
$handle = curl_init('https://'.$subdomain.'.chargify.com/customers/100000.json');
curl_setopt($handle, CURLOPT_USERPWD, $api_key . ":x");
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
describe Wombat do
context "with an active user" do
let(:active_user) do
user = User.new
user.tap(&:make_active)
end
it "is a cuddly creator" do
expect(Wombat.new(active_user)).to be_cuddly
end
describe Wombat do
let(:active_user) do
user = User.new
user.tap(&:make_active)
end
context "with an active user" do
it "is a cuddly creator" do
expect(Wombat.new(active_user)).to be_cuddly
end
require "spec_helper"
describe FuManchu do
let(:something_expensive) { Record.new.tap(&:save) }
let(:something_inexpensive) { OpenStruct.new(cheap: true) }
context "a stash" do
it "uses the something expensive" do
require "spec_helper"
# I would like to..
describe "a story." do
# there once was a chicken
it "was a lovely chicken" do
# you could always
expect(the_chicken).to cluck
end
require "minitest/autorun"
class ALongTest < Minitest::Test
def setup
@this_is_cool = true
end
def test_this_is_cool
assert @this_is_cool