This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FactoryGirl | |
def self.create_resource(*args) | |
resource = build(*args) | |
if resource.is_a?(ActiveResource::Base) | |
content = resource.class.format == ActiveResource::Formats::XmlFormat ? resource.to_xml : resource.to_json | |
ActiveResource::HttpMocks.respond_to do |mock| | |
mock.get resource.class.element_path(resource.id), {}, content, 200 | |
end | |
end | |
resource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
options = {} | |
options[:port] = 8888 | |
OptionParser.new do |opts| | |
opts.banner = "Usage: poh [options]" | |
opts.on "-p", "--port PORT", "Port (default is 8888)" do |port| | |
options[:port] = port |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in application.js | |
$.ajaxSetup({ | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); | |
} | |
}); | |
// in layout aka root template | |
<meta name="csrf-token" content="{ csrf_token}"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE categories_search; | |
DROP TABLE onebox_renders; | |
DROP TABLE post_onebox_renders; | |
DROP TABLE posts_search; | |
DROP TABLE users_search; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MagicPrint { | |
class Program { | |
static async void MagicPrint(string fileName) { | |
var buf = new byte[1024]; | |
var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, true); | |
int size = await fs.ReadAsync(buf, 0, buf.Length); | |
while (size > 0) { | |
Console.WriteLine(Encoding.UTF8.GetString(buf, 0, size)); | |
size = await fs.ReadAsync(buf, 0, buf.Length); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Type: MagicPrint.Program | |
// Assembly: MagicPrint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | |
// Assembly location: C:\Projects\Net\MagicPrint\MagicPrint\bin\Debug\MagicPrint.exe | |
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async void MagicPrint(string fileName) { | |
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, buf.Length, true); | |
int size = await fs.ReadAsync(buf, 0, buf.Length); | |
while (size > 0) { | |
Console.WriteLine(Encoding.UTF8.GetString(buf, 0, size)); | |
size = await fs.ReadAsync(buf, 0, buf.Length); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Print(string fileName) { | |
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, buf.Length, true); | |
fs.ReadAsync(buf, 0, 1024).Bind(PrintFuture); | |
} | |
public static int PrintFuture(int size) { | |
if (size > 0) { | |
Console.WriteLine(Encoding.UTF8.GetString(buf, 0, size)); | |
fs.ReadAsync(buf, 0, buf.Length).Bind(PrintFuture); | |
return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < Struct.new :id, :name | |
self.members.each do |member| | |
undef_method "#{member}=" | |
end | |
end | |
foo = Foo.new(1, "Adam") | |
puts foo.id # => 1 | |
foo.id = 2 # => ndefined method `id=' for #<struct Foo id=1, name="Adam"> (NoMethodError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
@@static_name = "Foo" | |
@instance_name = "Foo" | |
def self.static_name | |
@@static_name | |
end | |
def self.instance_name | |
@instance_name |