Skip to content

Instantly share code, notes, and snippets.

@mootari
mootari / class.php
Last active May 3, 2017 14:34
Barracuda/ArchiveStream: Wrapping remote files.
<?php
namespace Drupal\example;
class TarArchive extends \Barracuda\ArchiveStream\TarArchive {
public function add_remote_file($name, $path, $size, array $opt = array())
{
// send file header
$this->init_file_stream_transfer($name, $size, $opt);
// open input file
@mootari
mootari / snippet.php
Last active April 27, 2017 10:53
Drupal 7: Regenerate pathauto aliases for existing nodes (per type).
<?php
$type = 'my_node_type'; $nids = db_query('select nid from node where type = :type', array(':type' => $type))->fetchCol(); pathauto_node_update_alias_multiple($nids, 'bulkupdate', array('message' => TRUE));
@mootari
mootari / helper.php
Created April 26, 2017 12:51
Drupal 7: Get base query of a view
<?php
public static function getBaseQuery($view_name, $display_id, $clear_fields = false) {
$view = views_get_view($view_name)->copy();
// Set dummy input to avoid fetching input from $_GET.
$view->exposed_input = array('' => '');
$view->set_arguments(array());
$view->set_display($display_id);
// Make sure the exposed form is not rendered, otherwise we end up in a
@mootari
mootari / encode-params.php
Created March 8, 2017 14:04
drupal 7 parameter encoding / decoding
<?php
class MyUtils {
public static function getHash($string) {
return hash_hmac('sha256', $string, drupal_get_private_key(), false);
}
/**
* Helper function to encode and hash data.
*/
(function() {
function parseSelectors(rule, index) {
rule.selectorText.split(/, */).map(function(t) {
var p = /\.[A-z0-9-_]+/g, m;
while(m = p.exec(t)) {
if(!index.hasOwnProperty(m[0])) {
index[m[0]] = 0;
}
index[m[0]]++;
}
@mootari
mootari / .block
Last active November 5, 2022 15:16
dat.GUI color scheme selection
license: mit
@mootari
mootari / .block
Last active November 23, 2016 00:26
Squaring the circle, part 2
license: mit
@mootari
mootari / .block
Created November 19, 2016 14:37
Squaring the circle, part 1
license: mit
height: 500
scrolling: yes
@mootari
mootari / .block
Last active November 9, 2016 20:33
text to music
license: mit
border: no
scrolling: yes
height: 500
@mootari
mootari / .block
Last active November 2, 2016 18:58
Reflection
license: mit