Skip to content

Instantly share code, notes, and snippets.

View eiriksm's full-sized avatar
💭
I may be slow to respond.

Eirik Stanghelle Morland eiriksm

💭
I may be slow to respond.
  • Frontkom / Violinist.io
  • Trondheim, Norway
  • 04:25 (UTC +02:00)
  • X @orkj
View GitHub Profile
@eiriksm
eiriksm / gist:a82f797a40d7b7466027
Created July 27, 2014 11:42
ssh to drush sql-cli
$ ssh myuser@remotemachine.com "drush --root=/path/in/remote/server sql-dump" | drush sql-cli
<?php
$style = '';
foreach($styles as $stylesheet) {
if (strpos($stylesheet['data'], 'system/system.menus.css') > 0) {
// Skip this one, at least for my theme.
continue;
}
// The following are nicked from Drupal core.
$contents = drupal_load_stylesheet($stylesheet['data'], TRUE);
@eiriksm
eiriksm / nodes.services.js
Last active August 29, 2015 14:04
Creating nodes with services module
function getLocationAndPost() {
'use strict';
navigator.geolocation.getCurrentPosition(function (position) {
var url = 'http://example.com/enpoint' + '/node.json'; //endpoint URL
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var date = new Date();
var timestamp = Math.round(date.getTime() / 1000);
var node_object = {
"type": "some_type", //set this to your content type
@eiriksm
eiriksm / drupal-vhost-install.sh
Created July 27, 2014 16:46
virtual host ++ drupal
#!/bin/bash
# Configuration
VHOST_CONF=/etc/apache2/sites-available/
ROOT_UID=0
WWW_ROOT=/var/www
MYSQL=`which mysql`
DRUSH=`which drush`
# If you don't use drush aliases, uncomment this.
DRUSHRC=/home/MYUSERNAME/.drush/aliases.drushrc.php
@eiriksm
eiriksm / vcl
Last active August 29, 2015 14:08
Drupal 8 and varnish
if (req.http.host == "crashndash.com") {
unset req.http.Cookie;
}
@eiriksm
eiriksm / html.tpl.php
Created November 2, 2014 15:01
template print
<?php
print client_cache_styles($css);
print client_cache_scripts($scripts);
@eiriksm
eiriksm / my_module.module
Created November 2, 2014 15:08
environment check
<?php
if (variable_get('environment', '') == 'development') {
return;
}
@eiriksm
eiriksm / my_module.module
Created November 2, 2014 15:12
Programatically creating webforms
<?php
/**
* Implements hook_node_insert().
*/
function mymodule_node_insert($node) {
// The node type I am using is called 'order'.
if ($node->type == 'order') {
// I am using the body field for values.
$body = field_get_items('node', $node, 'body');
$comp = explode("\n", $body[0]['value']);
@eiriksm
eiriksm / my_module.module
Created November 2, 2014 15:14
Fixing descriptions
<?php
/**
* Implements hook_webform_component_presave().
*/
function mymodule_webform_component_presave(&$component) {
// Maybe I should do some more robust checking here, but this is a simple site
// and the body description clearly states how to format lines with links.
// Also, remember if you have other use cases for the webform, you should
// check that this is actually a webform created by above code!
if (strpos($component['name'], '(http') > -1) {
@eiriksm
eiriksm / tpl.php
Created November 2, 2014 15:23
First style hack
<?php
print '<style>';
$style = ''
foreach ($css as $c) {
// Do some checking of some media query stuff.
// ...
// Then store the raw CSS.
$style .= file_get_contents($c['data']);
}
//do some regex to remove some stuff, and remove whitespace.