Skip to content

Instantly share code, notes, and snippets.

@nickjacob
nickjacob / ConvertDispatchToMs.m
Created February 28, 2017 19:51
Convert dispatch_time_t to NSNumber (ms)
/**
* Convert a dispatch_time_t to milliseconds.
* note that this only works if dispatch time is in the future,
* and is approximate (since the time now will be slightly different than
* the time you made the dispatch_time_t).
*/
static NSNumber * dispatch_future_to_ms(dispatch_time_t time) {
uint64_t abs = mach_absolute_time();
return @((time - abs) / NSEC_PER_MSEC);
}
@nickjacob
nickjacob / prebid-gearheads-granularity.js
Created December 21, 2016 15:39
gearheads prebid price granularity code
// around line 341 on homepage template
var bidderSettings = {
brealtime: {
bidCpmAdjustment : function(bidCpm){
// adjust the bid in real time before the auction takes place
return bidCpm * .80;
}
},
rubicon: {
bidCpmAdjustment : function(bidCpm){
@nickjacob
nickjacob / sendgrid_sender.rb
Created August 13, 2016 05:52
using sendgrid4r to create a custom ActionMailer delivery method that uses the sendgrid v3 api
require 'mail/check_delivery_params'
require 'sendgrid4r'
class SendgridSender
include ::Mail::CheckDeliveryParams
def initialize(options = {})
@api_key = options[:api_key]
end
@nickjacob
nickjacob / deploy.js
Created July 30, 2016 17:31
Using ember-cli-deploy-s3 with Google Cloud Storage
// you can use Google Cloud storage's interoperability functionality
// to use the standard aws-sdk adapter in ember-cli-deploy-s3.
module.exports = function(deployTarget) {
// make your own client so yo ucan set the 'endpoint' to google
var googUploadClient = new AWS.S3({
endpoint: 'https://storage.googleapis.com',
accessKeyId: process.env.GOOGLE_ACCESS_KEY,
secretAccessKey: process.env.GOOGLE_SECRET_KEY,
bucket: '< your bucket name >',
region: 'us-east-1', // won't affect anything in google cloud
@nickjacob
nickjacob / json-api-rails-errors.md
Created June 19, 2016 09:19
Monkey patch rails to output json-api compatible validation errors using respond_with

Using respond_with and json-api

ActiveModel::Serializer makes it easy to output json-api compatible models, but if you try to respond with validation errors your 422 response will not be in json-api format, which will break compatible tools (e.g., Ember adapters)

You can monkey-patch rails so that respond_with formats validation errors correctly (since ActiveModel::Error already has enough information to be useful in json-api).

Just add an initializer that overrides ActionController::Responder#json_resource_errors:

@nickjacob
nickjacob / ember-to-native.js
Last active November 21, 2023 08:35
How to convert an Ember object to a regular javascript object
// an Ember.Object is typeof 'function'/a class
// which can make serialization difficult (e.g., there are issues passing
// to jQuery's serialization
// using Object.assign
// (& es6 syntax)
Ember.Object.reopen({
toNative() {
return Object.assign({}, this);
},
@nickjacob
nickjacob / pre-commit
Created February 15, 2016 20:43
Git pre-commit hook to prevent users from committing on master
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
rep_char() {
printf %${1}s |tr " " "$2"
@nickjacob
nickjacob / inline-sdk-prebid.md
Last active February 5, 2016 15:55
How to inline third-party SDKs in Prebid.js

Inlining Bidder SDKs in Prebid

To improve performance in Prebid (or any other header bidding setup), you can inline third-party SDKs/resources that are required to make bids. This removes network requests/roundtrips which can have a significant impact (especially on mobile) — cutting down time to first bid request.

One way to inline the scripts as part of your build process is to replace calls to adloader.loadScript with a preprocessor directive that downloads the script and inlines its contents into the page. See below for instructions, with AOL/ADTECH as an example.

gulp-preprocess & request

Add gulp-preprocess & request: npm install --save-dev gulp-preprocess request, this will let you add preprocessing directives to the code, and add the request

@nickjacob
nickjacob / quant-refresh.js
Created January 19, 2016 21:12
Quantcast - Manually trigger refresh
// load the quantcast quant.js
// replace w/ actual url
(function (s, h, src) {
window._qQue = window._qQue || [];
function _exec(fn){ fn(window.__qc); }
s.onload = function () {
window._qQue.forEach(_exec);
window._qQue.push = _exec;
};
s.src = src;
@nickjacob
nickjacob / tlvmedia-decoded.js
Created December 2, 2015 15:13
TLVMedia - Fraudulent Creative
var originalCreative="<img src='http://bidder-us-east-6.tlvmedia.com/newbidder/plsil.gif?subid=23ee43BOH1BYRq8QhcUdoTBgB1NGdXNWVaMmdVdWFQZVpJejhzcHJ3ICAgICAgICDZzsNAY%5F1aAQEAAAAAALDRcwEAZQAAAAAAAgABAAAAEgAAAAAAAAAAAAAAAAAAAEoHX1YAAAAAAAAAAAAAAAAAAAAAAAAAAPjYVADv2KRQZW5OWQEA&cost=${dap}&subid2=0bf1aHR0cDovL2FwbHVzLmNvbS9hL2JhbGFuZy1lbGxlbi1kZWdlbmVyZXMtc2hvdy1wZXJmb3JtYW5jZT9saV9zb3VyY2U9TEkmbGlfbWVkaXVtPXRyZW5kaW5nLXdpZGdldD9wYmpzX2RlYnVnPXQ%7E' width='1' height='1'/><div style="overflow:hidden;width:728px;height:90px;margin:0;padding:0;visibility:visible;border:none;display:inline-block;">
<div id="rtbmain411480"><a href="http://bidder.tlvmedia.com/newbidder/click.php?subid=23ee43BOH1BYRq8QhcUdoTBgB1NGdXNWVaMmdVdWFQZVpJejhzcHJ3ICAgICAgICDZzsNAY%5F1aAQEAAAAAALDRcwEAZQAAAAAAAgABAAAAEgAAAAAAAAAAAAAAAAAAAEoHX1YAAAAAAAAAAAAAAAAAAAAAAAAAAPjYVADv2KRQZW5OWQEA&redir=aHR0cDovL3d3dy53aXguY29tL2V0ZWFtaHRtbC8zMDAtbmV3P3V0bV9jYW1wYWlnbj1tYV90bHZtZWRpYSZleHBlcmltZW50X2lkPSRQQVJBTSQ~&subid2=0bf1aHR0cDovL2FwbHVzLmNvbS9hL2Jh