Skip to content

Instantly share code, notes, and snippets.

View davidbarratt's full-sized avatar

David Barratt davidbarratt

View GitHub Profile
@davidbarratt
davidbarratt / migrate.php
Last active October 12, 2023 00:31
Migrate Drupal SQLite to MySQL
<?php
use Drupal\Core\Database\Database;
$sqlite = Database::getConnection('default');
$mysql = Database::getConnection('mysql');
$schema = $sqlite->query("SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%'")->fetchCol();
$tables = [
{
"@context": {
"@vocab": "",
"jsonapi": {
"@id": "https://jsonapi.org/",
"@prefix": true,
"@context": {
"@vocab": "https://jsonapi.org/"
}
},
@davidbarratt
davidbarratt / covidratio.txt
Last active September 13, 2020 18:51
APIs for COVID Ratio
# Population of Every Florida County
https://api.census.gov/data/2019/pep/population?get=POP&for=county:*&in=state:12
# Number of cases in a Florida county within a date range
# @TODO I'm not sure which datetime field is the correct one to be looking at, there are at least 3.
https://services1.arcgis.com/CY1LXxl9zlJeBuRZ/arcgis/rest/services/Florida_COVID19_Case_Line_Data_NEW/FeatureServer/0/query?where=County+%3D+%27Orange%27+AND+Case1+%3E%3D+TIMESTAMP+%272020-03-18+00%3A00%3A00%27+AND+Case1+%3C%3D+TIMESTAMP+%272020-04-27+23%3A59%3A59%27&returnCountOnly=true&f=json
# Case count for given time range broken down by Florida county
https://services1.arcgis.com/CY1LXxl9zlJeBuRZ/arcgis/rest/services/Florida_COVID19_Case_Line_Data_NEW/FeatureServer/0/query?where=EventDate+%3E%3D+TIMESTAMP+%272020-08-30+00%3A00%3A00%27+AND+EventDate+%3C%3D+TIMESTAMP+%272020-09-12+23%3A59%3A59%27&f=json&outStatistics=%5B%7B+%09%22statisticType%22%3A+%22count%22%2C+%09%22onStatisticField%22%3A+%22ObjectId%22%2C+%09%22outStatisticFie
const initialState = {
search: '',
};
function reducer(state, action) {
switch (action.type) {
case 'CHANGE':
return {
...state,
[action.name]: action.value
@davidbarratt
davidbarratt / rxjs-hooks.js
Last active August 4, 2019 03:33
RxJS with React Hook
function createSearchSubject() {
return (new Subject()).pipe(
// Whatever you want to do, but the end result should be an action object.
)
}
const initialState = {
search: '',
};
<App>
<MetaHeader>
<Ad />
</MetaHeader>
<Header>
<Logo />
<Menu>
<Link />
<Link>
<Menu>
@davidbarratt
davidbarratt / Import.php
Created February 28, 2015 22:34
Entity Export using Serialization
<?php
use Drupal\serialization\Normalizer\ContentEntityNormalizer;
use Drupal\serialization\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncode;
$data = file_get_contents('node.xml');
@davidbarratt
davidbarratt / export.php
Last active August 29, 2015 14:16
Entity Export
<?php
$data = \Drupal\Component\Serialization\Yaml::decode(file_get_contents('node.yml'));
$entity_type = \Drupal::entityManager()->getDefinition('node');
if ($entity_type->hasKey('bundle')) {
$data[$entity_type->getKey('bundle')] = $data[$entity_type->getKey('bundle')][0]['target_id'];
}