Skip to content

Instantly share code, notes, and snippets.

View eduardinni's full-sized avatar
🚲

Eduardo Lomelí eduardinni

🚲
View GitHub Profile
@eduardinni
eduardinni / youtubeID.rb
Last active July 31, 2022 12:39 — forked from takien/youtubeID.js
Get YouTube ID from various YouTube URL using Ruby
# Get YouTube ID from various YouTube URL
# Ruby port from JavaScript version: https://gist.github.com/takien/4077195/
def get_youtube_id(url)
id = ''
url = url.gsub(/(>|<)/i,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/)
if url[2] != nil
id = url[2].split(/[^0-9a-z_\-]/i)
id = id[0];
else
@eduardinni
eduardinni / GIF-Screencast-OSX.md
Created December 22, 2016 04:52 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@eduardinni
eduardinni / apache.conf
Last active March 13, 2019 22:09
PageSpeed apache conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
@eduardinni
eduardinni / encoding-video.md
Created July 5, 2018 22:39 — forked from Vestride/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@eduardinni
eduardinni / react-native-ios-splash.m
Created July 8, 2019 21:49 — forked from benvium/react-native-ios-splash.m
React Native iOS Smooth Splash Screen (when using LaunchScreen.xib)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
...
...
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MyAwesomeApp"
initialProperties:@{}
launchOptions:launchOptions];
@eduardinni
eduardinni / my_code_example_1.md
Last active January 10, 2020 00:33
Code examples

3rd-party API as data source (Ruby)

Get data from Stripe API and calculates MRR (Monthly Recurring Revenue) for every customer. Each customer could have one or more subscriptions. A subscription could be monthly or yearly, also it could have a discount (percent or fixed amount). Also the data source could return with not paid subscriptions (delinquency)

require "stripe"
require "terminal-table"

class Metrics
@eduardinni
eduardinni / my_code_example_2.md
Created January 10, 2020 00:42
Code example 2

Database sync, using data streams (JavaScript)

This is a simple AWS Lambda function to syncronize data from DynamoDB to ElasticSearch, it is triggered via DynamoDB streams. Also transforms data types.

const fetch = require('node-fetch');
const es_url = "https://elasticsearch.us-east-1.es.amazonaws.com";

exports.handler = async (event) => {
@eduardinni
eduardinni / my_code_example_4.md
Created January 10, 2020 00:58
MapReduce function

Calculate most used hashtags (JavaScript)

AWS Lambda function to calculate most used hashtags from an Instagram account. The Instagram posts are stored in a DynamoDB table.

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
var mapreduce = require('mapred')(1);
@eduardinni
eduardinni / my_code_example_5.md
Last active March 9, 2024 08:54
Ruby on Rails JWT

Ruby on Rails API authorization via JWT

ApplicationController that defines methods to authorize requests based on JWT, also defines Error handling

class ApplicationController < ActionController::API
  before_action :authenticate
  before_action :set_current_user_refs
  before_action :authorize

JavaScript testing

Unit testing for Node.js / Redux using Jest

// State Management
const createStore = require('redux').createStore;
const applyMiddleware = require('redux').applyMiddleware;
const thunk = require('redux-thunk').default;
const reducers = require('../reducers');