Skip to content

Instantly share code, notes, and snippets.

@rhrn
rhrn / rpn
Created September 12, 2012 08:09
Reverse Polish notation on PHP
<?php
function rpn($params) {
$params = explode(' ', $params);
$count = sizeof($params);
$result = null;
@rhrn
rhrn / imgsrc-errorlog-server.js
Last active April 5, 2017 10:18
Send javascript errors to server
var errorLog = function errorLog(msg, url, line) {
var i = document.createElement('img');
i.src = '/error/log?msg=' + encodeURIComponent(msg) + '&url=' + encodeURIComponent(url) + '&line=' + encodeURIComponent(line);
};
window.onerror = errorLog;
@rhrn
rhrn / ubuntu tips
Last active December 10, 2015 19:48
Ubuntu tips
# ubuntu-repair-broken-package
sudo dpkg --force-depends --purge [package]
sudo apt-get autoremove -f
sudo apt-get install [package]
# enable do-release-upgrade command
sudo apt-get install update-manager-core
# enable add-apt-repository command
sudo apt-get install software-properties-common
@rhrn
rhrn / build-twitter-bootstrap-nixway
Last active December 13, 2015 22:59
Build Twitter Bootstrap
// x - project
// required install uglifyjs, less (via npm better way)))
//
// sudo npm install less uglifyjs -g
git clone git://github.com/twitter/bootstrap.git
cd bootstrap
mkdir -p x/css x/js x/img
[user]
name = User Name
email = user@ema.il
[alias]
co = checkout
br = branch
st = status
cm = commit -m
cam = commit --amend
ds = diff --staged
@rhrn
rhrn / Bandwidth throttling in OS X
Created April 26, 2013 15:00
Development tips
# creates a pipe that only allows up to 15KB/s to go through.
sudo ipfw pipe 1 config bw 15KByte/s
# will attach that pipe to the outgoing traffic on port 80, effectively limiting the outgoing traffic of the web server.
sudo ipfw add 1 pipe 1 src-port 80
# will remove the pipe from the port.
sudo ipfw delete 1
@rhrn
rhrn / gist:5650788
Created May 25, 2013 21:06
Read file chunks
// set chunk size
var chunkSize = 1024 * 1024 * 2; // 2Mb
// file from input
var readChunks = function(file) {
var parts = [];
var start = 0;
var stop = chunkSize - 1;
var chunksLength = Math.ceil(file.size / chunkSize);
@rhrn
rhrn / spinner-directive.js
Created January 30, 2014 14:45
Angular.js directives
fzapp.directive('xspin', [function() {
return {
scope: true,
link: function(scope, element, attrs) {
var spinner, options = {lines:10, width: 1, length: 1, radius: 7};
if (attrs.xspin) {
options = angular.extend(options, angular.fromJson(attrs.xspin));
@rhrn
rhrn / mailgun-signature-generator.js
Created November 10, 2015 10:19
Generate mailgun email signature in node.js
var crypto = require('crypto');
var mailgunSignature = function(mailgunApiKey) {
var token = crypto.randomBytes(25).toString('hex');
var timestamp = Math.floor(Date.now() / 1000);
return {
token: token,
timestamp: timestamp,
@rhrn
rhrn / redux_async.js
Created May 1, 2016 11:21
Redux async example
/*
* Redux async actions examples
*
* Install
npm install bluebird redux redux-thunk
*/
const Promise = require('bluebird');