Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / error.md
Last active August 20, 2018 17:03
Applaud Tag Error

Uncaught TypeError: Cannot set property 'onclick' of null at (index):1

@mrded
mrded / export2csv.js
Created June 1, 2018 17:16
Export test to CSV files.
#!/usr/bin/env node
const fs = require('fs');
const csvLine = require('csv-line');
const readFile = function(file) {
return new Promise(function(resolve, reject) {
fs.readFile(file, 'utf8', function(err, data) {
err ? reject(err) : resolve(JSON.parse(data));
});
@mrded
mrded / foo.js
Last active June 1, 2018 11:46
chai-spies: How to test async callbacks
const Chai = require('chai');
const Spies = require('chai-spies');
Chai.use(Spies);
const original = function(callback) {
setTimeout(callback, 0);
};
it("async callback should be called with Spy", function() {
@mrded
mrded / benchmark.sh
Created February 10, 2017 17:59
Simple wrapper around Apache benchmark
#!/bin/bash
# Copy into /usr/local/bin/benchmark
# Give permissions: chmod +x /usr/local/bin/benchmark
# Usage: `benchmark http://example.com`
ab -n20 -c1 $1 | grep 'Requests per second\|Time per request\|Transfer rate\|Total transferred'
@mrded
mrded / foo.php
Last active April 15, 2016 04:59
Drupal 7 - Useful hook_update_N
<?php
/**
* Uninstall modules.
*/
function foo_update_7001() {
module_disable(array('module1', 'module2'));
drupal_uninstall_modules(array('module1', 'module2'));
}
@mrded
mrded / foo.js
Created March 11, 2016 14:19
AngularJS 1.x & ui.router: How to show 404 stage by staying on the same URL.
angular.config(function($urlRouterProvider, $stateProvider) {
$stateProvider.state('404Page', { template: '404' });
$urlRouterProvider.otherwise(function($injector, $location) {
$injector.get('$state').go('404Page', {}, { location: false });
return $location.path();
});
});
@mrded
mrded / sublime-keymap.json
Last active February 10, 2016 15:21
Sublime config.
[
{ "keys": ["super+shift+backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["super+d"], "command": "duplicate_line" },
{ "keys": ["super+shift+up"], "command": "swap_line_up" },
{ "keys": ["super+shift+down"], "command": "swap_line_down" },
{ "keys": ["super+shift+n"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["super+shift+alt+n"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
@mrded
mrded / backup.sh
Created January 18, 2016 20:22
Drupal: backup script
#!/bin/bash
USER='root'
PASS='root'
DATABASE='drupal'
# Create folders if it's not yet.
mkdir -p ~/backups/{database,files}
# Backup.
@mrded
mrded / server.js
Created December 4, 2015 16:17
CORS Proxy on node.js + express
var express = require('express'),
request = require('request');
var app = express();
// Forward all requests from /api to http://foo.com/api
app.use('/api', function(req, res) {
req.pipe(request("http://foo.com/api" + req.url)).pipe(res);
});
@mrded
mrded / crontab
Last active November 4, 2016 01:47
Dammit simple Internet Radio Player with a scheduler
# New Year
59 23 31 12 * mplayer http://happy-year.narod.ru/mp3/kurant.mp3
0 0 1 1 * mplayer http://media.kremlin.ru/1999_12_31_01s.mp3
# Every morning - Chill Out (7:00 - 9:00)
0 7 * * 1-5 mplayer http://air2.radiorecord.ru/chil_320
0 9 * * 1-5 pkill mplayer
# Every evening - Chill Out (19:00 - 22:00)
0 19 * * 1-5 mplayer http://air2.radiorecord.ru/chil_320