Skip to content

Instantly share code, notes, and snippets.

@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
@mrded
mrded / phantomjs
Last active December 24, 2020 12:10
Run phantomjs as a deamon
#! /bin/sh
# /etc/init.d/phantomjs
case "$1" in
start)
phantomjs --webdriver=4444 &
;;
stop)
pkill phantomjs
@mrded
mrded / keybindings.json
Last active January 17, 2017 14:28
VS Code config.
[
{ "key": "shift+cmd+backspace", "command": "editor.action.deleteLines", "when": "editorTextFocus" },
{ "key": "cmd+d", "command": "editor.action.copyLinesDownAction", "when": "editorTextFocus" },
{ "key": "shift+cmd+down", "command": "editor.action.moveLinesDownAction", "when": "editorTextFocus" },
{ "key": "shift+cmd+up", "command": "editor.action.moveLinesUpAction", "when": "editorTextFocus" },
{ "key": "cmd+shift+n", "command": "workbench.action.quickOpen" },
{ "key": "cmd+1", "command": "workbench.view.explorer" },
{ "key": "cmd+5", "command": "workbench.view.debug" }
]
@mrded
mrded / gist:5f62cb52e60f1173cdb5
Created February 12, 2015 15:45
Drupal: Get wildcard (node/%node/edit) of the path (node/5/edit).
<?php
/**
* Get menu wildcard from path.
*
* @param $path
* The path, for example node/5/edit.
*
* @return
* Returns wildcard node/%node/edit.
@mrded
mrded / gist:c832366d58848f0ff11d
Created February 6, 2015 10:15
Drupal: Create a Node in Code
<?php
function my_create_a_node() {
global $user;
// entity_create replaces the procedural steps in the first example of
// creating a new object $node and setting its 'type' and uid property
$values = array(
'type' => 'YOUR_NODE_TYPE',
'uid' => $user->uid,
'status' => 1,
@mrded
mrded / qtsconverter.rb
Last active August 29, 2015 14:14
Ruby: QuickTapSurvey to MailChimp converter.
#!/usr/bin/env ruby
# https://gist.github.com/mrded/17317466b3ebf71eb07a
require 'csv'
class MailChimpConverter
attr_accessor :columns
COLUMNS_HEADER = {
@mrded
mrded / foo.php
Created January 21, 2015 15:24
Drupal: Set header data (title, metatags).
<?php
// Insert into page callback.
drupal_add_html_head(array(
'#tag' => 'title',
'#value' => 'new header title',
), 'foo_title');
drupal_add_html_head(array(
'#tag' => 'meta',
'#attributes' => array(
@mrded
mrded / foo.js
Created January 15, 2015 12:49
JS: Remove Duplicates from JavaScript Array
jobtypes = jobtypes.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});
@mrded
mrded / callback.js
Created January 4, 2015 18:38
JS: Function with callback.
function httpGet(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
callback.call(this, JSON.parse(xmlHttp.responseText));
}
};
xmlHttp.open("GET", url, false);