Skip to content

Instantly share code, notes, and snippets.

@pofat
pofat / ProtocolNotofication.swift
Last active December 15, 2021 10:50
Deal with notification with protocol-oriented programing in Swift
//: Playground - noun: a place where people can play
import UIKit
// This is for dmoe, you can use a generice type to limit your observer to an UIViewController for common usage.
protocol Notifiable {
var name: Notification.Name { get }
func observe(by observer: Any, withSelector selector: Selector, object: Any?)
func post(object: Any? ,userInfo: [AnyHashable: Any]?)
static func remove(observer: Any)
echo "USAGE: rpi-netflix.sh workdirectory"
echo "THIS ASSUMES YOU HAVE CHROMIUM!!!"
echo "IF NOT, PRESS CTRL+C"
sleep 5
wget https://dl.google.com/dl/edgedl/chromeos/recovery/linux_recovery.sh
echo "YOU MUST HAVE ENOUGH FREE SPACE!!!"
echo "14\n" | sudo WORKDIR=$1 ./linux_recovery.sh
cd $1
sudo apt-get install kpartx
sudo kpartx -avs chromeos*.bin
echo "USAGE: rpi-netflix.sh workdirectory"
echo "THIS ASSUMES YOU HAVE CHROMIUM!!!"
echo "IF NOT, PRESS CTRL+C"
sleep 5
wget https://dl.google.com/dl/edgedl/chromeos/recovery/linux_recovery.sh
echo "YOU MUST HAVE ENOUGH FREE SPACE!!!"
echo "14\n" | sudo WORKDIR=$1 ./linux_recovery.sh
cd $1
sudo apt-get install kpartx
sudo kpartx -avs chromeos*.bin
@jesstelford
jesstelford / netflix-rpi.md
Last active April 4, 2020 17:52
Netflix on Raspberry Pi (incomplete)

Note: as @clibois mentioned below, due to the DRM Netflix uses, all decoding has to be done in CPU, making it somewhat choppy.

Note 2: Even the RPi 3 suffers from these CPU limitations. There is the potentially risky option of overclocking your RPi 3, but I haven't tried this.

If you manage to get smooth playback, please contact me, or post your solution here

UPDATE: I can no longer get this method to work. I have tried using Chromium v47, and v48, and both result in Netflix error "Oops, something went wrong" / C7053-1807, for which I can find no description online. If you manage to get things up and running, please contact me!

OSMC

@amitpdev
amitpdev / adjust_gpx_to_apple_format.awk
Created September 16, 2015 17:17
Use this awk script to adjust standard GPX files downloaded from any site (bikes) into a GPX format that is supported by Xcode.
awk '
BEGIN {
buffer=""
}
{
gsub(/<\/*trk>/,"",$0)
gsub(/<\/*trkseg>/,"",$0)
gsub(/<trkpt/,"<wpt", $0)
gsub(/<\/trkpt>/,"<\/wpt>", $0)
print
@JacksonTian
JacksonTian / Node.js异步处理CPU密集型任务.md
Last active March 16, 2020 04:01
Node.js异步处理CPU密集型任务

Node.js异步处理CPU密集型任务

Node.js擅长数据密集型实时(data-intensive real-time)交互的应用场景。然而数据密集型实时应用程序并不是只有I/O密集型任务,当碰到CPU密集型任务时,比如要对数据加解密(node.bcrypt.js),数据压缩和解压(node-tar),或者要根据用户的身份对图片做些个性化处理,在这些场景下,主线程致力于做复杂的CPU计算,I/O请求队列中的任务就被阻塞。

Node.js主线程的event loop在处理所有的任务/事件时,都是沿着事件队列顺序执行的,所以在其中任何一个任务/事件本身没有完成之前,其它的回调、监听器、超时、nextTick()的函数都得不到运行的机会,因为被阻塞的event loop根本没机会处理它们,此时程序最好的情况是变慢,最糟的情况是停滞不动,像死掉一样。

一个可行的解决方案是新开进程,通过IPC通信,将CPU密集型任务交给子进程,子进程计算完毕后,再通过ipc消息通知主进程,并将结果返回给主进程。

和创建线程相比,开辟新进程的系统资源占用率大,进程间通信效率也不高。如果能不开新进程而是新开线程,将CPU耗时任务交给一个工作线程去做,然后主线程立即返回,处理其他的I/O请求,等到工作线程计算完毕后,通知主线程并将结果返回给主线程。那么在同时面对I/O密集型和CPU密集型服务的场景下,Node的主线程也会变得轻松,并能时刻保持高响应度。

//Origional code from http://www.ediy.com.my/index.php/blog/item/74-digispark-infrared-receiver
//Modified by Daniel Splawski 02/11/2013
//Uncomment DigiKeyboard statments for debugging
//#include <DigiKeyboard.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0,1); // RX, TX
int irPin = 2; //Sensor pin connect to digital pin2 (ATINY85 pin7)
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/python");</script>
@Wollw
Wollw / adc_example.c
Created April 16, 2012 06:00
ATmega328P ADC conversion example
/* A simple ADC example that checks the analog reading on ADC0 and turns
* an LED on if the reading is higher than a threshold value and turns if
* off if it is under that value. */
#include <avr/io.h>
#include <stdint.h>
/* Which analog pin we want to read from. The pins are labeled "ADC0"
* "ADC1" etc on the pinout in the data sheet. In this case ADC_PIN
* being 0 means we want to use ADC0. On the ATmega328P this is also
* the same as pin PC0 */