MacRuby Pointer to typedef struct - ruby

this code fails with Semgentation Fault: 11, and I can't understand why
framework 'Cocoa'
framework 'CoreFoundation'
framework 'Security'
* keychainObject = Pointer.new_with_type('^{OpaqueSecKeychainRef}')
SecKeychainOpen("/Users/charbon/Library/Keychains/Josja.keychain",keychainObject)
SecKeychainLock(keychainObject)
I'm sure it has to do with the keychainObject type, because this works (it locks the default keychain).
SecKeychainLock(nil)
I'm using the '^{OpaqueSecKeychainRef}' as the type of pointer because that's what the debugger told me it expected when I used a wrong type of pointer.
I hope solving this would help grasping the macruby / cocoa magic.
For reference, the complete output is
cobalt:~ charbon$ macirb Desktop/test.rb
irb(main):001:0> framework 'Cocoa'
=> true
irb(main):002:0> framework 'CoreFoundation'
=> true
irb(main):003:0> framework 'Security'
=> true
irb(main):004:0> * keychainObject = Pointer.new_with_type('^{OpaqueSecKeychainRef}')
=> [#<Pointer:0x4007ac200>]
irb(main):005:0> SecKeychainOpen("/Users/charbon/Library/Keychains/Josja.keychain",keychainObject)
=> 0
irb(main):006:0> SecKeychainLock(keychainObject)
Segmentation fault: 11

If you were writing C you would have written
SecKeychainRef keyChainRef;
SecKeychainOpen("/path/to/...", &keychainRef);
SecKeychainLock(keyChainRef);
i.e. while SecKeychainOpen requires a pointer to a SecKeychainRef (so that the output parameter can be filled in), other apis just require a SecKeychainRef, so you need to dereference the pointer:
framework 'Security'
keychainObject = Pointer.new_with_type('^{OpaqueSecKeychainRef}')
SecKeychainOpen("/Users/charbon/Library/Keychains/Josja.keychain",keychainObject)
SecKeychainLock(keychainObject.value)

Related

.Net Core 3 HtmlGrid WithFooter not an option

I am a noob when it comes to .Net Core and I was asked to upgrade an existing project from Core 2.2 to 3.1. I have been slowly working though the issues but this one I can not find any help on.
I am getting an error:
CS1061 'IHtmlGrid' does not contain a definition for
'WithFooter' and no accessible extension method 'WithFooter' accepting
a first argument of type 'IHtmlGrid' could be found (are
you missing a using directive or an assembly reference?)
Here is the full page code from my FollowupOnTimeGrid.cshtml:
#(Html.Grid(Model)
.Build(c =>
{
c.Add(m => m.SurveyDateRange).Titled("Survey Period").InitialSort(GridSortOrder.Asc);
c.Add(m => m.Due);
c.Add(m => String.Format("{0} ({1:f2}%)", m.OnTime, m.Due == 0 ? 0
: Math.Round((((double)m.OnTime) / m.Due) * 100.0, 2)))
.Titled("Surveys Taken on Time (N (%))");
})
.Css("table-striped table-bordered table-hover")
.Named("FollowupOnTimeGrid")
.Empty("No Records Found!")
.WithFooter("_FollowupOnTimeGridFooter")
)
I was able to find the solution. NonFactor changed the .WithFooter to .UsingFooter in release 7.

Using Ruby & Github API to filter commits by date

I am using the ruby gem 'octokit' which implements the Github API v3. Mostly works great but I cannot seem to filter by date. I believe I have the syntax and time format correct, but it appears my option is ignored and the API returns the past 35 entries regardless of the since or until dates.
Here's a minimal reproducible example (after installing the octokit gem).
require 'octokit'
require 'time'
#day = "2012-09-27"
#until = DateTime.parse(#date).iso8601
#since = (DateTime.parse(#day) - 60*60*48).iso8601
a = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => #since, :until => #until})
see the date of the output of last entry
a.last.commit.author.date
explicit day doesn't work either
b = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => "2012-09-27T00:00:00+00:00"})
b.last.commit.author.date
The date I get in both examples is from August, outside the specified range given. What did I miss?
Background: I'm trying to write a little Jekyll plugin that uses the API to return commits made to a specified repo on the day of the post.
joeyw gives a great answer to this question here.
The second argument should be the sha or branch, and options should be the third argument, e.g.
Octokit.commits("cboettig/labnotebook", "master", :since => "2012-09-28T00:00:00+00:00").length
or
Octokit.commits("cboettig/labnotebook", nil, :since => "2012-09-28T00:00:00+00:00").length
works just fine. Here's my corresponding jekyll plugin

Jade in ExecJS context

Very simply, I am having trouble running the compiled jade.js from jade-lang file in execjs.
If I include jade.js in an html file
jade.compile
returns a function.
When I do the following:
require 'execjs'
source = <<-src
var window = {};
#{open('jade.js').read}
var jade = window.jade;
src
context = ExecJS.compile source
context.eval "jade.compile"
=> nil
nil gets returned by eval.
Any idea where I'm going wrong? I've searched stack overflow, and even found a few gems that do this the same way as I am doing it, but when I execute on my system, it doesn't work. I've tried with therubyracer and node as my execjs runtimes.
Thanks for your help!
It appears that when the return from execjs is a function, it returns nil. So:
context.eval "jade.compile.toString()"
=> "function....."
Likewile
context.eval "jade.compile(#{template.to_json}).toString()"
=> "function...."
and
context.eval "jade.compile(#{template.to_json})()"
=> "some html"
This makes sense since the extract_result method of execjs/external_runtime.rb (line 62 as of this writing) uses JSON.decode, which will not decode a function. Only a derivative of object.

StructureMap Class Chaining - Stack Overflow or other errors

This has completely baffled me on a number of configurations. I keep reading the documentation, and I just don't get it. Here is my registration code:
ForRequestedType<SimpleWorkItemProcessor>().TheDefault.Is.OfConcreteType<SimpleWorkItemProcessor>();
ForRequestedType<WorkItemRetryProcessor>().TheDefault.Is.OfConcreteType<WorkItemRetryProcessor>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<SimpleWorkItemProcessor>())
.WithCtorArg("busyDelay").EqualTo(TimeSpan.FromMilliseconds(20))
.WithCtorArg("overallTimeout").EqualTo(TimeSpan.FromSeconds(60));
ForRequestedType<WorkItemQueue>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());
As it is, it says there's no default instance for IWorkItemProcessor (which is correct). Switching the last line to this:
ForRequestedType<IWorkItemProcessor>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());
...Makes a stack overflow exception.
How do you chain classes together that both implement an interface, and take in that same interface in their constructor?
This works, but I can't explain why. From what I know, the first version should work just as well.
ForRequestedType<SimpleWorkItemProcessor>().TheDefault.Is.OfConcreteType<SimpleWorkItemProcessor>();
var retryProcessor = ForRequestedType<WorkItemRetryProcessor>().TheDefault.Is.OfConcreteType<WorkItemRetryProcessor>()
.CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<SimpleWorkItemProcessor>())
.CtorDependency<TimeSpan>("busyDelay").Is(x => x.Object(TimeSpan.FromMilliseconds(20)))
.CtorDependency<TimeSpan>("overallTimeout").Is(x => x.Object(TimeSpan.FromSeconds(60)));
ForRequestedType<IWorkItemProcessor>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
.CtorDependency<IWorkItemProcessor>("workItemProcessor").Is(x => x.Instance(retryProcessor));

IronRuby is_a with DateTime

Can anybody explain why DateTime in IronRuby is Object[]
sample code
IronRuby 0.9.1.0 on .NET 2.0.50727.4927
Copyright (c) Microsoft Corporation. All rights reserved.
>>> require 'System'
=> true
>>> t = System::DateTime.Now
=> Thu Dec 03 15:32:42 +05:00 2009
>>> t.is_a?(Time)
=> true
>>> t.is_a?(System::DateTime)
=> true
>>> t.is_a?(System::Object)
=> true
>>> t.is_a?(System::Object[])
=> true
>>> t.is_a?(System::Decimal)
=> false
Using [] for generic types is a justifiable syntax for Ruby, but the current behavior you see (using [] on a non-generic type) is a open bug: http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3355
In Ruby, square brackets are only used for indexing into an array, not define a type-array ... as there is no need for defining the type of a Ruby array. Ruby allows overloading whatever [] means against any object, and Ruby's Class object doesn't have a meaning for [], so we've defined [] to mean getting a generic type. Keep in mind that the of method is the preferred method to use; [] is really only there for convenience and similar syntax with IronPython.
Because System::Object[] is not really an array type. t.is_a?(System::DateTime[]) will return true as well.
I think that what happens here, is that IronRuby considers the square brackets as empty generic type indicators (because creating a generic type is done with the same syntax, for example, System::Collections::Generic::List[String].new).
The right way to do so is as follows:
IronRuby 0.9.3.0 on .NET 2.0.50727.4927
Copyright (c) Microsoft Corporation. All rights reserved.
>>> t = System::DateTime.new
=> 01/01/0001 00:00:00
>>> t.is_a? System::Array.of(System::Object)
=> false

Resources