Skip to content

Instantly share code, notes, and snippets.

View pedrorocha-net's full-sized avatar

Pedro Rocha pedrorocha-net

  • Lisboa, Portugal
View GitHub Profile
@pedrorocha-net
pedrorocha-net / laravel_media_library_migrate.php
Created February 17, 2022 20:00
Laravel + Media Library code to migrate files from local filesystem to AWS S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Spatie\MediaLibrary\Models\Media;
class MigrateFiles extends Command
{
protected $signature = 'migrate-files';
@pedrorocha-net
pedrorocha-net / sparkar_tap_counter_persistence.js
Last active January 8, 2021 14:25
Spark AR script that uses Persistence module to save the number of taps a user does on screen
const Scene = require('Scene');
const Persistence = require('Persistence');
const Diagnostics = require('Diagnostics');
const Patches = require('Patches');
// Esperamos por todos os itens que iremos usar do SparkAR ficarem disponíveis
Promise.all([
Patches.outputs.getPulse('wasTapped'),
Scene.root.findFirst('2dText0'),
]).then(results => {
@pedrorocha-net
pedrorocha-net / color_generator.php
Created April 24, 2018 02:01
PHP file to randomly generate a color palette
<style>
div {
float: left;
width: 12.5%;
padding: 40px 0;
line-height: 30px;
text-align: center;
color: #fff;
font-family: Verdana;
}
@pedrorocha-net
pedrorocha-net / gulpfile.coffee
Created July 15, 2016 16:53
Setup for SASS with Gulp
gulp = require 'gulp'
$ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'run-sequence']
});
sources =
sass: 'docroot/sites/all/themes/nylottery/assets/scss/**/*.scss'
destinations =
@pedrorocha-net
pedrorocha-net / mymodule.d7.password.php
Created November 11, 2015 21:49
Code to help migrate Drupal 7 users to Drupal 8
<?php
/**
* @file
* Secure password hashing functions for user authentication.
*
* Based on the Portable PHP password hashing framework.
* @see http://www.openwall.com/phpass/
*
* An alternative or custom version of this password hashing API may be
@pedrorocha-net
pedrorocha-net / hook_schema.php
Created August 16, 2015 20:28
Approach using hook_schema (as on Drupal 7)
$schema['votingapi_vote'] = array(
'fields' => array(
'vote_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
@pedrorocha-net
pedrorocha-net / baseDefinitionApproach.php
Created August 16, 2015 20:26
Approach extending ContentEntityBase and using BaseFieldDefinition::create
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Voting API Vote entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Voting API Vote entity.'))
@pedrorocha-net
pedrorocha-net / gist:511d4fc33bc5f0eaee03
Created July 5, 2015 01:43
Fix videos data retrieve for Popcorn Time 0.3.7.2 for Mac
var Q = require('q'),
os = require('os'),
path = require('path'),
_ = require('underscore'),
data_path = require('nw.gui').App.dataPath;
/** Default settings **/
var Settings = {};
// User interface
@pedrorocha-net
pedrorocha-net / gist:f7fe05a018b8e1917577
Created March 2, 2015 11:14
Drupal Search module customisation to allow display priority settings for each content type (to allow showing certain types first in the default search module)
function HOOK_ranking() {
$rankings = array();
$types = node_type_get_types();
foreach ($types as $type) {
$rankings[$type->type . '_node_type_boost_search'] = array(
'title' => t('Boost "' . $type->name . '" nodes'),
'arguments' => array(':type' => $type->type),
'score' => ' FIND_IN_SET(n.type, :type)',
);
}
@pedrorocha-net
pedrorocha-net / gulp-drupal-concat-js
Created February 4, 2015 16:14
Gulp task to concatenate all JS files from a Drupal website active modules with Gulp + Coffeescript + Drush
drush = require 'drush-node'
destinations =
js: 'assets/js'
gulp.task 'drupal-minifyjs', ->
drush.init()
.then () ->
drush.exec('php-eval "print realpath(\'.\')"')
.then (realpath) ->