Skip to content

Instantly share code, notes, and snippets.

@pettomartino
pettomartino / styledExtended.tsx
Last active August 9, 2020 15:56
Use styled components with LinearGradient and pass props
const Background = styled(LinearGradient).attrs(() => ({
colors: ['#464769', '#1B1A1F'],
}))`
padding-top: 50px;
flex: 1;
`
@pettomartino
pettomartino / view.controller.tsx
Created December 16, 2019 11:42
Authenticate controller
import { Context, dependency, Get, render, TokenRequired } from '@foal/core';
import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import { User } from '../entities';
import { TypeORMStore } from '@foal/typeorm';
export class ViewController {
@dependency
store: TypeORMStore;
@pettomartino
pettomartino / retry.js
Last active March 12, 2019 18:14
Retry promise
const retry = (fn, options = {}) => new Promise((resolve, reject) => {
const { retryInterval = 500, retries = 1 } = options;
fn()
.then(resolve)
.catch(err => (
(retries === 0)
? reject(err)
: setTimeout(
() => retry(fn, { retryInterval, retries: retries - 1 }).then(resolve, reject),
retryInterval,
@pettomartino
pettomartino / script.conf
Created May 22, 2018 08:14
execute a command on start up ubuntu
# save it on /etc/init
start on startup
task
exec /path/to/command
<html>
<head>
<script>
function myFunc() {
var email = document.getElementById("email").value
var e = document.getElementById("select")
var selectedOption = e.options[e.selectedIndex].value
var checkBox = document.getElementById('defaultCheck1').checked
if (email == 'foo@bar' && checkBox && selectedOption == "audi") {
browser
.setValue('input[placeholder=E-mail]', email)
.setValue('input[placeholder=Password]', password)
.useXpath()
.click("//*[text()='Login']")
.pause(200)
.expect.element("//*[text()='John Doe']").to.be.present
browser
.setValue('.input-text', email)
.setValue('input.input-text[type=password]', password)
.click('.btn-success')
.pause(200)
.assert.urlEquals(url)
.end()
class MockPromise {
then(fn) {
this.thenFn = fn
return this
}
catch(fn) {
this.catchFn = fn
return this
}
@pettomartino
pettomartino / gist:6425ede3460758b3e54d
Created September 25, 2014 00:12
Packer log error with parallels
petto@mac ~/dev/bento/packer (master●)$ packer build --only=parallels-iso debian-7.6-amd64.json [ruby-2.1.1]
parallels-iso output will be in this color.
==> parallels-iso: Downloading or copying ISO
parallels-iso: Downloading or copying: http://cdimage.debian.org/debian-cd/7.6.0/amd64/iso-cd/debian-7.6.0-amd64-CD-1.iso
==> parallels-iso: Starting HTTP server on port 8081
==> parallels-iso: Creating virtual machine...
==> parallels-iso: Executing: prlctl [create packer-debian-7.6-amd64 --distribution debian --dst packer-debian-7.6-amd64-parallels --vmtype vm]
==> parallels-iso: Executing: prlctl [set packer-debian-7.6-amd64 --cpus 1]
==> parallels-iso: Executing: prlctl [set packer-debian-7.6-amd64 --memsize 512]
var cursor = db.places.find();
while (cursor.hasNext()) {
var x = cursor.next();
x['source']['url'].replace('aaa', 'bbb'); // is this correct?
db.foo.update({_id : x._id}, x);
}