Skip to content

Instantly share code, notes, and snippets.

View pbjorklund's full-sized avatar

Patrik Björklund pbjorklund

View GitHub Profile
@pbjorklund
pbjorklund / interfacesandclasses.ts
Last active May 23, 2016 16:38
Interfaces and classes
// Interface and class
export interface Printer {
print(text: string): string;
}
export class Logger implements Printer {
// Need to make it public to work in examples above.
// I would like to keep it private but then compiler complains
constructor(public logFunction = (text: string) => { return text; } ) { }
The node ambient module defines a require with type NodeRequire which means that var require : any will claim that it needs type NodeRequire.
Doesn't seem like requirejs typings define RequireConfig anymore either?
var require = {
paths: {
"jquery": "../bower_components/jquery/dist/jquery"
}
};
var qsKeys = Request.QueryString.AllKeys;
if (qsKeys.Contains("SPAppWebUrl"))
{
AppWebUrl.Value = Request.QueryString["SPAppWebUrl"];
}
else
{
var rootUri = new UriBuilder(String.Concat(new Uri(Request.QueryString["SPHostUrl"]).Authority, "/sites/apps"))
{
// vars from init
// , companyParam = { symbol: "TEST1" }
// , quoteParams = [{ close: 123 }, { close: 12 }, { close: 123 }]
it('can create quotes with companies', function(done) {
db.Company.create(companyParam).success(function (company) {
quoteParams.map(function (item) {
item.CompanyId = company.id;
});
class Tester
def test statement, &block
puts "Running test with #{statement}"
block.call
puts "Continuing test"
end
end
tester = Tester.new
tester.test("string param") { puts "Running block" }
Hi,
Today, the Pingdom team deployed a software upgrade to some of our
monitoring probes. Despite thorough testing, this upgrade contained a
malfunction that led to false down alerts being sent to a portion of our
customers, including you.
Even if the issue affected monitoring for less than 90 minutes for a
limited number of customers, it's of course frustrating if you were one
of them. We take a lot of pride in delivering a reliable service and
@pbjorklund
pbjorklund / form_hack.rb
Created May 18, 2012 14:29
Horrible form hack getting all attr_accessible from model
module FormHelper
def errors_for model, field
if model.errors[field].present?
content_tag :span, :class => 'error_explanation' do
model.errors[field].join(", ")
end
end
end
def text_fields_for f, model
@pbjorklund
pbjorklund / git_blame_repo.sh
Created February 28, 2012 18:31
Sorted git blame on repo
# From http://stackoverflow.com/questions/4589731/git-blame-statistics
# Performs a git blame on the repo and sorts the results
git ls-tree -r HEAD | gsed -re 's/^.{53}//' | \
while read filename; do file "$filename"; done | \
grep -E ': .*text' | gsed -r -e 's/: .*//' | \
while read filename; do git blame "$filename"; done | \
ruby -ne 'puts $1.strip if $_ =~ /^\w{8} \((.*?)\s*\d{4}-\d{2}-\d{2}/' | \
sort | uniq -c | sort -rg
@pbjorklund
pbjorklund / triangle.rb
Created January 28, 2012 15:33
Fun with ruby koans triangle class
def triangle(*args)
[:equilateral, :isosceles, :scalene][args[0..2].uniq.size-1]
end
def triangle(a,b,c)
[:equilateral, :isosceles, :scalene].fetch([a,b,c].uniq.size - 1)
end
@pbjorklund
pbjorklund / avdi_vcr_screencast_transcription
Created January 20, 2012 10:18
Transcript of avdi's vcr screencast
http://avdi.org/devblog/2011/04/11/screencast-taping-api-interactions-with-vcr/
== What is it
Testing web apps. Modern web apps are more often then not interconnected and talking with at least one RESTful api. These can be social networking sites, url shorteners, payment gateways etc.
This presents an interesting problem when it comes to high level integration testing. There are a few different approaches to testing on this level.
* Live testing - Talking directly to external sources
Slow, makes continuous integration a pain
Dependant on the services, can be in maintenance mode