Skip to content

Instantly share code, notes, and snippets.

View Thorsson's full-sized avatar
🎯
Focusing

Ivan Turkovic Thorsson

🎯
Focusing
View GitHub Profile
@Thorsson
Thorsson / ofPropertyPathChanges.js
Created February 1, 2017 14:26 — forked from jayphelps/ofPropertyPathChanges.js
RxJS observable of property value changes, given an object and property path
function isObject(value) {
// Avoid an old bug in Chrome 19-20
// See https://code.google.com/p/v8/issues/detail?id=2291
const type = typeof value;
return type === 'function' || (!!value && type === 'object');
}
function ofPropertyChanges(obj, key) {
if (isObject(obj) === false) {
return Rx.Observable.return(undefined);
@Thorsson
Thorsson / Gemfile
Created January 17, 2017 15:27 — forked from goncalvesjoao/Gemfile
Changes you need to make in order to make Devise use JWT Header Authentication
# Add the "https://github.com/jwt/ruby-jwt" gem to your "Gemfile"
gem 'jwt'
@Thorsson
Thorsson / README.md
Created October 25, 2016 08:46 — forked from pbojinov/README.md
Two way iframe communication

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@Thorsson
Thorsson / wantsJSON.js
Created September 13, 2016 14:30 — forked from leereamsnyder/wantsJSON.js
Detect if a request in Express is for HTML or JSON
/*
Usage:
var jsoncheck = require('./wantsJSON') // path to file with this middleware function
app.use(jsoncheck)
app.get('/', function(req,res,next){
if (req.wantsJSON) {
// serve JSON
}
if (req.wantsHTML) {
@Thorsson
Thorsson / Dockerfile
Created August 9, 2016 18:36 — forked from yefim/Dockerrun.aws.json
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
# Example Dockerfile
FROM hello-world
@Thorsson
Thorsson / gist:47b073b83f082c221d0bbb3c4bca6ec7
Created May 1, 2016 21:32 — forked from kublaios/gist:f01cdf4369c86ddd6d71
Making a PEM File for iOS Push Notifications (From Ray Wenderlich's tutorial)
# Convert the .cer file into a .pem file:
$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
# Convert the private key’s .p12 file into a .pem file:
$ openssl pkcs12 -nocerts -in PushChatKey.p12 -out PushChatKey.pem
# Finally, combine the certificate and key into a single .pem file
$ cat PushChatCert.pem PushChatKey.pem > ck.pem
# At this point it’s a good idea to test whether the certificate works.

Develop locally with Elasticsearch on OSX using Docker

Docker

Docker does not run natively on OSX, only Linux. Docker Machine was created to add a Linux VM environment to run Docker containers on OSX. Install using Homebrew:

brew install docker
brew install docker-machine
docker-machine create
@Thorsson
Thorsson / postgresql-on-aws-tips.md
Created December 30, 2015 17:06 — forked from juliandunn/postgresql-on-aws-tips.md
Notes on PostgreSQL performance optimization on RDS

Deep Dive: PostgreSQL on AWS

When loading data

  • disable backups (backup_retention=0)
  • disable multi-AZ and autovacuum
  • pg_dump -Fc (compressed) and pg_restore -j (parallel)
  • Increase maintenance_work_mem
@Thorsson
Thorsson / gist:2cc454cdaa16cf18bcb6
Created October 18, 2015 13:46 — forked from bryanluby/gist:548beba8f8062c81ed68
Static variable inside of a function in Swift.
func staticInsideFunction() {
struct Temp { static var hasAnimated = false }
if Temp.hasAnimated == false {
// ... do something only on the first function call.
Temp.hasAnimated = true
} else {
// ... do something on all subsequent function calls.
}
}
@Thorsson
Thorsson / facebook_throttle.rb
Created October 13, 2015 13:48 — forked from pboling/facebook_throttle.rb
Facebook API Rate Limit Throttler using Sidekiq, does not execute the job inside the lock, to maintain some semblance of performance, just marks it in a counter, which other jobs from the same queue and using the same token will also update, and which will be throttled. Jobs from other queues will not be able to bust the lock until the timer run…
# Mixin to (i.e. include in) any worker class that does FB API calls and should be throttled.
module FacebookThrottle
def perform_throttled(*args, &block)
options = args.extract_options!
user = User.find_by_fb_uid(options[:fb_uid])
if user
if !user.valid_facebook_token? # A bitwise flag managed by flag_shih_tzu gem
puts "Skipping #{self.class} #{user.fb_uid}: Invalid Oauth Token for #{user}"
return false