Skip to content

Instantly share code, notes, and snippets.

@hrmoller
hrmoller / secure_random_string.sh
Last active April 13, 2024 10:56
Cryptographically Secure Random String
# based on answer in this post: https://security.stackexchange.com/questions/183948/unix-command-to-generate-cryptographically-secure-random-string
LC_ALL=C tr -dc '[:alnum:]' < /dev/urandom | head -c61

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@hrmoller
hrmoller / space-consumption.sh
Last active August 29, 2015 14:27
sudo du -d 1 -h | sort -h
sudo du -d 1 -h | sort -h
@hrmoller
hrmoller / removeDrupalHashes.php
Last active August 29, 2015 14:04
Remove Drupal hash strings on CSS/JS files
function THEME_process_html(&$vars) {
if (variable_get('environment') == 'development' && !stristr($_GET['q'],'flush-cache')) {
$vars['styles'] = preg_replace('/\.css\?.*"/','.css"', $vars['styles']);
$vars['scripts'] = preg_replace('/\.js\?.*"/','.js"', $vars['scripts']);
}
}
var fs = require('fs');
var file = __dirname + '/test.json';
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
@hrmoller
hrmoller / lines_of_php_code
Last active December 17, 2015 08:59
Lins of code in php project on Linux // OSX
On a POSIX operating system (e.g. Linux or OS X) you can write the following into your Bash shell:
wc -l `find . -iname "*.php"`
//source:
//http://stackoverflow.com/questions/790956/count-lines-in-a-php-project
@hrmoller
hrmoller / gist:5574764
Created May 14, 2013 09:27
Parse object into array (Drupal JSON)
private function parseFields($object) {
if (is_object($object)) {
$object = (array)$object;
}
if (is_array($object)) {
$arr = array();
foreach ($object as $key => $val) {
if ($key !== '@') {
$arr[$key] = $this->parseFields($val);
}
@hrmoller
hrmoller / save_unmanaged.php
Last active December 15, 2015 19:08
Save unmanaged file in Drupal 7
$data = drupal_json_encode($SOME_ARRAY);
$path = drupal_get_path('module', '[MODULE_NAME]') . '/test/mockup/FILE_NAME.json';
file_unmanaged_save_data($data, $path, FILE_EXISTS_REPLACE);
@hrmoller
hrmoller / twitter.js
Created March 16, 2013 13:43
twitter
db.users.findOne({"services.twitter.id":""});