Skip to content

Instantly share code, notes, and snippets.

View cms's full-sized avatar

Christian C. Salvadó cms

View GitHub Profile
@cms
cms / Optimizar.js
Last active January 10, 2020 14:55
import _ from "lodash"
import React from "react"
import moment from "moment"
import { connect } from "react-redux"
import API from "@Services/Api/profile"
import { ApiManager } from "../../api/apiManager"
import ParsedText from "react-native-parsed-text"
import { NavigationEvents } from "react-navigation"
import { DateToWordsFromNow } from "../../helpers/helper"
import { ACTIVITY_NOTIFICATION } from "../../api/constants"
import _ from "lodash";
import React from 'react';
import moment from 'moment';
import { connect } from 'react-redux';
import API from '@Services/Api/profile';
import { ApiManager } from "../../api/apiManager";
import ParsedText from 'react-native-parsed-text';
import { NavigationEvents } from "react-navigation";
import { DateToWordsFromNow } from '../../helpers/helper';
import { ACTIVITY_NOTIFICATION } from "../../api/constants";
@cms
cms / getCurrentPosition.js
Created August 13, 2019 18:08
navigator.geolocation.getCurrentPosition promise
function getCurrentPosition(options) {
return new Promise(function(resolve, reject) {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
}
(async () => {
const position = await getCurrentPosition().catch(err => console.log(err));
console.log(position);
})();
@cms
cms / debounce.js
Created July 24, 2019 19:14
Small debounce function
/**
* Small debounce function.
*
* by Christian C. Salvadó <c@cms.gt>
* MIT Style license, 2019
*/
function debounce(fn, ms = 0) {
let timer = 0
@cms
cms / fetch-timeout.js
Last active June 4, 2019 16:45
fetch with cancellation at timeout using AbortController
export default function fetchWithTimeout(url, options, timeout = 3000) {
const controller = new AbortController()
const { signal } = controller
setTimeout(() => controller.abort(), timeout)
return fetch(url, { ...options, signal })
}
@cms
cms / capitalizeSentence.js
Last active May 10, 2019 22:14
capitalizeSentence
function capitalizeSentence(str) {
return str.replace(/^\w|(\s\w)/g, function(match, index) {
return match.toUpperCase()
});
}
capitalizeSentence('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
// "Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing Elit."
@cms
cms / array-chunks.js
Created March 22, 2019 18:59
array chunks
// Using Array.prototype.reduce:
const getChunks = (array, size) => {
return array.reduce((acc, curr, i) => {
const pos = Math.floor(i/size);
acc[pos] = [...(acc[pos]||[]), curr];
return acc
}, [])
}
// Using Array.from:
@cms
cms / devicons.html
Created February 26, 2019 02:57
DevIcons
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css">
<link href='//cdn.jsdelivr.net/devicons/1.8.0/css/devicons.min.css' rel='stylesheet'>
<style>
body {
@cms
cms / main.cs
Created December 6, 2018 17:35
360TRef
using System.Linq;
using System.Text.RegularExpressions;
using ServiceStack;
using ServiceStack.Text;
var mysisRef = "360T364827992x";
var _360tRef = Get360TReference(mysisRef);
_360tRef.PrintDump();
@cms
cms / CasecadeDelete.sql
Created April 19, 2018 15:04 — forked from lionofdezert/CasecadeDelete.sql
Casecade Delete in SQL Server
USE AdventureWorks
GO
--============== Supporting function dbo.udfGetFullQualName
IF OBJECT_ID('dbo.udfGetFullQualName') IS NOT NULL
DROP FUNCTION dbo.udfGetFullQualName
GO
CREATE FUNCTION dbo.udfGetFullQualName ( @ObjectId INTEGER )