Skip to content

Instantly share code, notes, and snippets.

View pablolmiranda's full-sized avatar

Pablo Lacerda de Miranda pablolmiranda

View GitHub Profile
@pablolmiranda
pablolmiranda / playlist.sh
Created September 4, 2020 06:36 — forked from scarlson/playlist.sh
Bash script to create .m3u playlist files for all mp3s in subdirectories
#!/bin/bash
#
# bash script to create playlist files in music subdirectories
#
# Steve Carlson (stevengcarlson@gmail.com)
find . -type d |
while read subdir
do
rm -f "$subdir"/*.m3u
@pablolmiranda
pablolmiranda / functional_context.md
Last active August 15, 2020 05:48
Functional flow using context

Problem

The current approach to functional programming only takes into consideration one piece of data going through the pipeline. This approach makes a lot of sense when you have a very linear flow, where we mutate the data along the way. The code doesn't hold well when we need to create another piece of data and keep the original data to use downstream.

A simple example would be:

const consolidateFilters = (fieldSet) => {
  const value = concatFiltersAndParameters(fieldSet)
 return flow([set('filters', value), omit('parameters')])(fieldSet)
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@pablolmiranda
pablolmiranda / immutable-benchmark-test.js
Last active September 15, 2016 07:22
Immutable vs. Seamless-Immutable benchmark tests
var Benchmark = require('benchmark');
var Immutable = require('immutable');
var lodash = require('lodash');
var SeamlessImmutable = require('seamless-immutable');
var arr = [];
for (var i = 0; i < 200; i++) {
arr.push({
index: i,
name: 'Pittsburgh Pirates',
@pablolmiranda
pablolmiranda / Validate a BST
Created August 26, 2016 17:37
Check if a BST is valid
function isBST(root) {
return validate(root, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
}
function validate(node, min, max) {
if (node === null) {
return true;
}
if (node && node.value < min) {
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: ea355e3b-dfc9-384a-a95d-437255945026" -d '{"msg": "GetBadgeCountAndNumGroups"}' 'https://dev.iris.yahoo.com/pablolm-dev/rpc?v=1'
@pablolmiranda
pablolmiranda / mobile_detection_ext.js
Created August 10, 2012 14:44
Extending Modernizr to accept Mobile Detection
Titans.common.Device = Titans.oop.extend( Titans.oop.BaseClass, {
elements : {
html : null,
window : null
},
devices : [
{'name' : 'mobile', 'width' : {'min' : 0, 'max' : 480}},
{'name' : 'desktop', 'width' : {'min' : 480, 'max' : 10240}}
],
modernizr : null,
@pablolmiranda
pablolmiranda / mobiledetect.php
Created August 10, 2012 14:39
Mobile Detection
/**
* Mobile Detect
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class MobileDetect
{
protected $accept;
protected $userAgent;
protected $isMobile = false;