Skip to content

Instantly share code, notes, and snippets.

nickjacob / ConvertDispatchToMs.m
Created February 28, 2017 19:51
Convert dispatch_time_t to NSNumber (ms)
View ConvertDispatchToMs.m
* 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 / prebid-gearheads-granularity.js
Created December 21, 2016 15:39
gearheads prebid price granularity code
View prebid-gearheads-granularity.js
// 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 / sendgrid_sender.rb
Created August 13, 2016 05:52
using sendgrid4r to create a custom ActionMailer delivery method that uses the sendgrid v3 api
View sendgrid_sender.rb
require 'mail/check_delivery_params'
require 'sendgrid4r'
class SendgridSender
include ::Mail::CheckDeliveryParams
def initialize(options = {})
@api_key = options[:api_key]
nickjacob / deploy.js
Created July 30, 2016 17:31
Using ember-cli-deploy-s3 with Google Cloud Storage
View deploy.js
// 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: '',
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 /
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 / ember-to-native.js
Last active March 29, 2016 18:05
How to convert an Ember object to a regular javascript object
View ember-to-native.js
// 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)
toNative() {
return Object.assign({}, this);
nickjacob / pre-commit
Created February 15, 2016 20:43
Git pre-commit hook to prevent users from committing on master
View pre-commit
# 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 /
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 / quant-refresh.js
Created January 19, 2016 21:12
Quantcast - Manually trigger refresh
View quant-refresh.js
// 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.push = _exec;
s.src = src;
nickjacob / tlvmedia-decoded.js
Created December 2, 2015 15:13
TLVMedia - Fraudulent Creative
View tlvmedia-decoded.js
var originalCreative="<img src='${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="