Skip to content

Instantly share code, notes, and snippets.

@andremalan
andremalan / codepad-test-harness.js
Last active July 15, 2020 23:05
A test harness for code pad like environments.
let tests = [
[Math.max(1, 3), 3, 'can pass'],
[Math.max(1, 4), 3, 'can fail'],
];
tests.forEach((test) =>
console.log(
test[0].toString() === test[1].toString() ? 'pass!' : 'fail!',
'expected:',
test[1],
'result:',
{
report_items: [
{
mobile_search_referrals: 10,
tablet_search_referrals: 11,
desktop_search_referrals: 1678,
search_referrals: 1699,
mobile_internal_referrals: 2,
tablet_internal_referrals: 1,
@andremalan
andremalan / simplereach.md
Created August 11, 2015 15:16
Segment integration for SimpleReach

Getting Started

Once the Segment library is integrated with your site, toggle SimpleReach on in your Segment integrations, and add your PID that was given to you by the SimpleReach client services team.

curl 'http://webapi.simplereach.com/data/exports' -H 'Origin: http://www.simplereach.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,ga;q=0.6' -H 'SREMAIL: amalan@simplereach.com' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36' -H 'Content-Type: application/json; charset=UTF-8' -H 'SRTOKEN: TkMizDsxifJ7SKDAyGFb' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://www.simplereach.com/app/site/5437e8b7d70ba0f2a7000073/intel/reports?timeFrame=Jul%2016%2C%202015' -H 'Connection: keep-alive' -H 'X-FirePHP-Version: 0.0.6' --data-binary '{"export":{"status":null,"created_at":null,"filename":null,"url":null,"board_name":null,"board_id":"5437e8b7d70ba0f2a7000073","name":"IBM-export-brian","url_hash":null,"field":"articles","options":{"sort":"referrals","sort_dir":"desc","sort_network":"all","page":1,"per_page":30},"filters":{"time_frame":"Jul 16, 2015","published_at":"All
var server = sinon.fakeServer.create();
server.autoRespond = true;
server.autoRespondAfter = 100;
server.xhr.useFilters = true;
server.xhr.addFilter(function(method, url) {
//whenever the this returns true the request will not faked
var fake = true;
server.responses.forEach(function(response){
if(response.url === url){
@andremalan
andremalan / gist:5761770
Created June 11, 2013 23:37
Ember saving crazytown
Redbot.PostsNewFileRoute = Redbot.BaseQuickPostRoute.extend
events:
save: ->
post = @get("currentModel")
controller = @controllerFor('posts.newFile')
attachment = controller.get('attachment')
Ember.run.next @, ->
post.set('attachmentId', attachment.get('id'))
post.one 'didCreate', =>
Ember.run.next @, ->
@andremalan
andremalan / gist:4560895
Created January 17, 2013 23:31
serializer that has sideloading
//serializer
class PostSerializer < ActiveModel::Serializer
embed :ids
attributes :id, :title, :body, :thumbnail, :created_at, :profile_id
has_many :comments
has_many :hashtags
end