Skip to content

Instantly share code, notes, and snippets.

// install pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
// install virtualenv
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip
$ cd ~
//download and unzip opencv
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
$ unzip opencv.zip
//download and unzip opencv contributions
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
//Update existings packages
$ sudo apt-get update
$ sudo apt-get upgrade
//Install developers tools, including cmake
$ sudo apt-get install build-essential cmake pkg-config
//Install some image I/O packages for loading images
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get update
$ sudo apt-get upgrade
# app/services/PushNotifier
def self.sendPush(user)
@message = get_message()
if user.notification_data_id.present?
@notification_data = NotificationData.find(user.notification_data_id)
Webpush.payload_send(endpoint: @notification_data.endpoint,
message: @message,
p256dh: @notification_data.p256dh_key,
auth: @notification_data.auth_key,
@lachlanagnew
lachlanagnew / gist:30759d6d1936c80875ab9a8a334816fa
Last active June 6, 2019 14:20
Subscribe and register service worker
//app/views/content/index.html.erb
javascript:
var vapidPublicKey = new Uint8Array(#{Base64.urlsafe_decode64($vapid_public).bytes});
function checkNotifs(obj){
if (!("Notification" in window)) { //1
console.error("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
@lachlanagnew
lachlanagnew / gist:9386c0151d3ce486cdf008d97f6451a9
Last active December 20, 2017 05:06
Create service worker
// app/assets/javascript/serviceworker.js
self.addEventListener("push", function(event) {
var title = (event.data && event.data.text().split("-")[0]) || "Message recieved";
var body; body = event.data.text().split("-")[1];
var tag = "push-simple-demo-notification-tag";
var icon = 'logo.png';
event.waitUntil(
self.registration.showNotification(title, {
@lachlanagnew
lachlanagnew / gist:ba462f4f9122033d085e24cf15aa081d
Last active December 20, 2017 05:07
Add files that shall be accessed by the serviceworker
#config/initializers/serviceworker.rb
WebPushDemo::Application.configure do
config.serviceworker.routes.draw do
# map to assets implicitly
match "/serviceworker.js"
match "/manifest.json"
match "/logo.png"
end
end