Skip to content

Instantly share code, notes, and snippets.

View mec's full-sized avatar

Meyric Rawlings mec

  • London, UK
  • 19:16 (UTC +01:00)
View GitHub Profile
@mec
mec / mr_custom_pages.info
Created June 1, 2014 20:26
In Drupal 7 you want to provide a URL and a theme file in the module that can be overridden in a theme, the big gotcha here is the name convention in hook_theme()
name = Custom Pages Module
description = Provides routes and pages with custom themes.
core = 7.x
@mec
mec / mr_video_cam_date_fix
Created June 9, 2015 19:36
Bash script to loop over a directory and fix the exif data to the date from the file name.
#!/bin/bash
path=$1
for file in $1/*; do
echo $file
filename=$(basename "$file" .mov)
filename=${filename//-/:}
filename=${filename//;/:}
echo "$filename"
@mec
mec / ispalindrome.js
Last active August 29, 2015 14:27
Test if a word is a palindrome, the same forwards as backwards.
function isPalindrome(word) {
// split the word into array for easiness
var word1 = word.split("");
// log
console.log(word);
// last array index of the word to count backwards
var backwardsCounter = word.length - 1;
// loop over the word, once forwards, once backwards
// if any letters do not match, it's not a palindrome
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// Fibonacci
//Looping
// seeds are 0,1,0 or 1,0,1
console.log("Looping : \n");
var result = 0,
term1 = 1,
term2 = 0;
@mec
mec / remove image from cart
Created February 23, 2014 13:37
Took me ages to find this, using Ubercart 3.x, you want to remove the image from the cart display. Put this in your template.php
function example_form_alter(&$form, &$form_state, $form_id) {
// Alters the cart view form at /cart.
if ($form_id == 'uc_cart_view_form') {
// Hides the image column since courses don't have product images.
$form['items']['#columns']['image']['access'] = FALSE;
// Adds the label to the product description column from the image column.
$form['items']['#columns']['desc']['cell'] = t('Products');
}
}
@mec
mec / fizzBuzz.js
Last active September 15, 2017 14:19
Good old Fizz Buzz
'use strict';
// fancy version uses a object with key and values to compare.
function fizzBuzzFancy (count) {
const set = { 'fizz': 3, 'buzz': 5 };
for (let i = 1; i <= count; i++) {
let output = '';
for (let word in set) {
@mec
mec / .eslintrc.json
Last active September 15, 2017 15:06
My starter eslint config – semistandard!
{
"extends": "standard",
"rules": {
"semi": [2, "always"],
"no-extra-semi": 2
}
}
@mec
mec / .eslintrc.json
Last active October 6, 2017 07:57
ESLint for React
{
"extends": "semistandard",
"plugins": ["react"],
"settings": {
"react": {
"createClass": "createReactClass",
"pragma": "React",
"version": "16.0",
"flowVersion": "0.53"
}
@mec
mec / npm.md
Last active November 29, 2017 22:34
❤️ npm, tips

npm tips

Update npm

sudo npm update npm -g

List all global packages and versions, show only one level

npm ls -g --depth 0