Skip to content

Instantly share code, notes, and snippets.

View eduardinni's full-sized avatar
🚲

Eduardo Lomelí eduardinni

🚲
View GitHub Profile
@eduardinni
eduardinni / FontAwesomeIcon.tsx
Created May 9, 2024 07:45
react-native-fontawesome FontAwesomeIcon typescript
import React from 'react';
import { StyleProp, StyleSheet } from 'react-native';
import { icon } from '@fortawesome/fontawesome-svg-core';
import convert from '../util/converter';
import type { IconDefinition } from '@fortawesome/fontawesome-common-types';
import type {
IconParams,
Transform,
IconLookup,
Styles,
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing

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');
@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
@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_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_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 / 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 / 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 / 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