Skip to content

Instantly share code, notes, and snippets.

View PavelPenkov's full-sized avatar

Pavel Penkov PavelPenkov

  • InSales
  • Moscow, Russia
View GitHub Profile
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
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
// 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}">
DROP TABLE categories_search;
DROP TABLE onebox_renders;
DROP TABLE post_onebox_renders;
DROP TABLE posts_search;
DROP TABLE users_search;
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);
}
// 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;
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);
}
}
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;
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)
class Foo
@@static_name = "Foo"
@instance_name = "Foo"
def self.static_name
@@static_name
end
def self.instance_name
@instance_name