Skip to content

Instantly share code, notes, and snippets.

View jdtorregrosas's full-sized avatar
🎃
hexing

Julian Torregrosa jdtorregrosas

🎃
hexing
View GitHub Profile
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# some more ls aliases
alias l='ls -CF'
alias ll='ls -lg'
alias la='ls -A'
alias f='open -a Finder ./'
alias home='cd ~'
@jdtorregrosas
jdtorregrosas / tail-call-op-recursive-foreach.js
Last active April 10, 2019 19:22
Create a tail call optimized recursive for each
"use-strict"; // required for tail call opt
Array.prototype.forEachRecursive = function(cb) {
function forEach(array, cb) {
return forEachRec(array, 0, cb);
}
function forEachRec(array, start, cb) {
if (start > array.length - 1) return;
cb(array[start], start);
return forEachRec(array, start + 1, cb);
@jdtorregrosas
jdtorregrosas / mega-filter.js
Created April 9, 2019 22:36
Create a simple filter using iterations
Array.prototype.megaFilter = function(cb) {
const iterator = this[Symbol.iterator]();
const iteration = iterator.next();
const filteredArray = [];
iterate(iteration);
function iterate(iteration) {
if (iteration.done) return iteration;
if (cb(iteration.value)) filteredArray.push(iteration.value);
const nextIteration = iterator.next(iteration.value);
return iterate(nextIteration);
@jdtorregrosas
jdtorregrosas / promesify.js
Created April 4, 2019 21:50
Simple promises creation from callbacks API
/* Callbacks function */
const asyncFn = (i, success, error) => {
if (i === 0) return error('Failed!');
setTimeout(() => {
return success('Worked!!');
}, 1000);
};
/* Function call like in old times */
@jdtorregrosas
jdtorregrosas / RecyclerViewAdapter.kt
Created August 25, 2017 16:28
Recycler Adapter Android Kotlin Example
data class Item(val id: Long, val title: String, val url: String)
class RecyclerViewAdapter(val items: List<Item>, val listener: (Item) -> Unit) : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.recycler_item_row, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(items[position], listener)
override fun getItemCount(): Int = items.size
/*
* Copyright 2002-2010 Guillaume Cottenceau.
*
* This software may be freely redistributed under the terms
* of the X11 license.
*
*/
#include <unistd.h>
#include <stdlib.h>