Skip to content

Instantly share code, notes, and snippets.

View acatl's full-sized avatar

Acatl Pacheco acatl

  • ViacomCBS
  • New York, NY
View GitHub Profile
@acatl
acatl / foo.test.js
Last active January 5, 2023 17:50
jest mock debug.js module
/* eslint-env jest */
const mockDebug = jest.fn()
jest.mock('debug', () => {
return () => mockDebug
})
const foo = require('./foo')
describe('foo.bar', () => {
it('should testName', () => {
@acatl
acatl / snippets.js
Last active March 29, 2018 18:12
VSCode snippets
{
/*
// Place your snippets for JavaScript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
{
"title": "Hello Mundo"
}
{
"title": "Hello World"
}
@acatl
acatl / feature-toggles.json
Created August 3, 2017 01:57
feature-toggles
{
"showExclamation": true
}
Hello world!!
@acatl
acatl / gif-by-id.js
Last active March 3, 2017 15:56
get trending example
exports = {
'source:getTrending': {
url: 'http://api.giphy.com/v1/gifs/feqkVgjJpYtjy?api_key=dc6zaTOxFJmzC'
}
};
@acatl
acatl / main.js
Created March 2, 2017 15:18
Giphy's trending example
exports = {
'source:getTrending': {
url: 'http://api.giphy.com/v1/gifs/trending?api_key=dc6zaTOxFJmzC'
},
// get all images
'model:getAllImages': {
// will execute source:getTrending and pass it as the context
before: 'source:getTrending',
// because the service returns everything
// under 'data' property, this will access that path
function getPageTitle(ctx, done) {
const data = ctx.value;
const regex = new RegExp(/title>(.*?)<\/title>/g);
const title = data.match(regex);
done(null, {title: title});
}
exports = {
"source:everything": {
"url": "http://api.nick.com/api/v2/tv-schedule/?apiKey=nickjr.com&numberOfDays=2",
},
@acatl
acatl / find-style.js
Last active August 29, 2015 14:22
find ALL matching styles with matching values on a document
/*
* credit of `getMatchedStyle` method for stakoverflow's Qtax
* http://stackoverflow.com/questions/9730612/get-element-css-property-width-height-value-as-it-was-set-in-percent-em-px-et/9733051#9733051
*/
function getMatchedStyle(elem, property) {
// element property has highest priority
var val = elem.style.getPropertyValue(property);
// if it's important, we are done
if (elem.style.getPropertyPriority(property))