Skip to content

Instantly share code, notes, and snippets.

View brunormferreira's full-sized avatar
:octocat:
coding and learning

Bruno Ramires brunormferreira

:octocat:
coding and learning
View GitHub Profile
function maximizeFontSize(elem, maxWidth, maxHeight, opt_dontChangeFontSize) {
var canBeBigger,
display = elem.style.display,
fontSize = elem.style.fontSize,
font = elem.style.font,
computedFont = window.getComputedStyle(elem, null).getPropertyValue('font'),
doc = elem.ownerDocument,
parentNode = elem.parentNode,
tempParent = doc.createElement('div'),
nextSibling = elem.nextSibling,
function getVideoImage(path, secs, callback) {
var me = this, video = document.createElement('video');
video.onloadedmetadata = function() {
if ('function' === typeof secs) {
secs = secs(this.duration);
}
this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
};
video.onseeked = function(e) {
var canvas = document.createElement('canvas');
function on(elSelector, eventName, selector, fn) {
var element = document.querySelector(elSelector);
element.addEventListener(eventName, function(event) {
var possibleTargets = element.querySelectorAll(selector);
var target = event.target;
for (var i = 0, l = possibleTargets.length; i < l; i++) {
var el = target;
var p = possibleTargets[i];
@garystorey
garystorey / fadein.js
Created January 5, 2015 21:53
fadeIn.js
Element.prototype.fadeIn = function(callback) {
var ele = this,
opacity = ele.style.opacity = ele.style.opacity || 0.0,
fadeInLoop = null,
intervalTime = 10,
opacityAmount = 0.05;
ele.style.display = 'block';
// If the opacity is already greater than or equal to zero then there is nothing
# NPM CheatSheet.
# Super easy intall: npm comes with node now.
# To create your own npm package: https://www.npmjs.org/doc/misc/npm-developers.html
# More: https://www.npmjs.org/doc/
# 1. NPM Command Lines.
# Local mode is the default.
# Use --global or -g on any command to operate in global mode instead.
import React, { Component } from 'react';
import Candidate from './Candidate.js';
import Button from 'react-uikit-button';
export default class CandidateList extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this)
}
import React, { Component } from 'react';
import CandidateList from './Views/CandidateList.js';
import Candidate from './Views/Candidate.js';
import fetch from 'isomorphic-fetch';
import { Route, Switch } from "react-router-dom";
class ParentComponent extends Component {
constructor(props) {
super(props);
this.state = {
@adrianlemess
adrianlemess / Code snippets.md
Last active December 27, 2019 17:42
Angular Awesome List

Snippets

Component:

  • HTML
<div *ngIf="item.length > 0">
const numbers = [ 2, 4, 8, 9 ]
const addTwo = number => number + 1
const isMoreThan5 = number => number > 5
const result =
//numbers.filter(isMoreThan5)
filterArray(isMoreThan5, numbers)
//mapArray(addTwo, numbers
result
function filterArray(predicate, array) {
@ericelliott
ericelliott / promise-chaining.js
Last active April 3, 2020 02:13
Promise chaining behaviors
const wait = time => new Promise(
res => setTimeout(() => res(), time)
);
wait(200)
// onFulfilled() can return a new promise, `x`
.then(() => new Promise(res => res('foo')))
// the next promise will assume the state of `x`
.then(a => a)
// Above we returned the unwrapped value of `x`