Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian C. Salvadó cms

View GitHub Profile
View Optimizar.js
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"
View Optimizar
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 Aug 13, 2019
navigator.geolocation.getCurrentPosition promise
View getCurrentPosition.js
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 Jul 24, 2019
Small debounce function
View debounce.js
/**
* 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 Jun 4, 2019
fetch with cancellation at timeout using AbortController
View fetch-timeout.js
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
capitalizeSentence
View capitalizeSentence.js
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."
View array-chunks.js
// 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:
View devicons.html
<!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 {
View main.cs
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 Apr 19, 2018 — forked from lionofdezert/CasecadeDelete.sql
Casecade Delete in SQL Server
View CasecadeDelete.sql
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 )