Skip to content

Instantly share code, notes, and snippets.

@mallendeo
mallendeo / ajaxOverride.js
Created October 9, 2015 03:48
Override XMLHttpRequest
(function(send) {
XMLHttpRequest.prototype.send = function () {
var callback = this.onreadystatechange
this.onreadystatechange = function() {
if (this.readyState == 4) {
var responseURL = this.responseURL
if (responseURL.match(/https?:\/\/www\.youtube\.com\/watch\?v=.*/g)) {
console.log(responseURL)
}
}
@mallendeo
mallendeo / spotilocal.js
Last active November 16, 2017 15:50
Spotify API for built-in server
'use strict'
const axios = require('axios')
const PORT = 4380
const DEFAULT_RETURN_ON = ['login', 'logout', 'play', 'pause', 'error', 'ap']
// Must use capitalized header
const ORIGIN_HEADER = { 'Origin': 'https://open.spotify.com' }
'use strict'
const cheerio = require('cheerio')
const request = require('superagent')
const inacap = (jar = []) => {
const urls = {
login: 'https://adfs.inacap.cl/adfs/ls',
notas: 'https://siga3.inacap.cl/siga/portal_nl/alumnos/mis_notas/ajax_notas_alumno.asp',
horario: 'https://siga3.inacap.cl/Inacap.Siga.Horarios/Horario.aspx?SESI_CCOD=',
@mallendeo
mallendeo / package.json
Last active February 5, 2016 19:04
Grabar canales chilenos con node
{
"main": "recorder.js",
"dependencies": {
"fs-extra": "^0.24.0",
"request": "^2.61.0"
}
}
@mallendeo
mallendeo / README.md
Last active March 30, 2023 12:31
Get mic audio stream in real time and send it vía websockets to a server

Dependencies

sox, node

On Ubuntu/Debian:

sudo apt install sox nodejs

On macOS:

@mallendeo
mallendeo / sensor.js
Created June 26, 2016 06:03
Get gpio sensors (Raspberry PI)
import gpio from 'gpio';
export default const sensor = (pins = [
{ num: 3, name: 'gate' },
{ num: 4, name: 'door' }
]) => {
let sensors = [];
const init = () => {
pins.map(pin => {
@mallendeo
mallendeo / pdf-extract.js
Created August 10, 2016 02:38
Extraer imágenes de pdfs y guardarlas en subcarpetas
'use strict'
const fs = require('fs-extra')
const spawn = require('child_process').spawn
const originalPath = __dirname + '/pdfs/original'
const extractedPath = __dirname + '/pdfs/extracted'
fs.removeSync(extractedPath)
fs.copySync(originalPath, extractedPath)
@mallendeo
mallendeo / index.js
Last active October 23, 2016 19:12
Despegar Telegram bot
'use strict'
const fetch = require('node-fetch')
const TelegramBot = require('node-telegram-bot-api')
const bot = new TelegramBot(process.env.TELEGRAM_TOKEN, { polling: true })
const low = require('lowdb')
const fileAsync = require('lowdb/lib/file-async')
const db = low(`${__dirname}/data/db.json`, { storage: fileAsync })
@mallendeo
mallendeo / config.fish
Last active December 16, 2016 20:11
Fish functions collection
function sshtmux
ssh $argv -t 'tmux -CC a || tmux -CC'
end
function flushdns
sudo killall -HUP mDNSResponder
end
function tgfiles --description "tgfiles - will toggle hidden files and folders"
set showFiles "YES"
/opt/vc/bin/raspivid -vf -hf -ih -t 0 -ISO 800 -ex night -w 720 -h 405 -fps 24 -b 1000000 -o - | tee output_original.h264 | ffmpeg -re -i - -codec:v libx264 -profile:v baseline -preset ultrafast -b:v 64k -maxrate 64k -bufsize 64k -vf scale=320:240 output_file.mp4 -y
/opt/vc/bin/raspivid \
-vf -hf -ih -t 0 -ISO 800 -ex night \
-w 720 -h 405 -fps 24 -b 1000000 -o - | \
gst-launch-1.0 -v fdsrc \
! h264parse \
! omxh264dec \
! omxh264enc \
! rtph264pay \