Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bondarewicz on github.
  • I am bondarewicz (https://keybase.io/bondarewicz) on keybase.
  • I have a public key ASBexiynXvVUuVgIhEjgNngIk-Cf5pb7D5Tb2_2Z_qBgbQo

To claim this, I am signing this object:

@bondarewicz
bondarewicz / gist:fd6864c18397874aa219
Last active August 29, 2015 14:18
price elasticity of demand
//http://en.wikipedia.org/wiki/Price_elasticity_of_demand
//In general, the demand for a good is said to be inelastic (or relatively inelastic) when the PED is less than one (in absolute value):
//that is, changes in price have a relatively small effect on the quantity of the good demanded.
//The demand for a good is said to be elastic (or relatively elastic) when its PED is greater than one (in absolute value):
//that is, changes in price have a relatively large effect on the quantity of a good demanded.
//Revenue is maximized when price is set so that the PED is exactly one.
<?php
//http://refectoryofajumblesale.wordpress.com/2013/06/04/currying-php/
$add = function($a, $b, $c) {
return $a + $b + $c;
};
$add2 = curry($add, 2);
echo $add2(4, 5);
@bondarewicz
bondarewicz / gist:9932113
Created April 2, 2014 11:10
PHP: return any specific (2nd or 3rd largest) number from array
<?php
function whats_largest($arr, $idx)
{
sort($arr, SORT_NUMERIC);
return($arr[count($arr) - intval($idx)]);
}
$array = array();
@bondarewicz
bondarewicz / gist:9805660
Created March 27, 2014 11:39
OSX: Time machine backup to windows network drive
1. open drive utility and create new image using 'sparse bundle disk image' and save to desktop
2. unmount and copy to network drive destination (using terminal's go->connect to server)
3. delete the image from desktop and open copied image on network drive unsing drive utility, mount
4. open terminal and paste "defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1 && killall Finder"
5. then "sudo tmutil setdestination /Volumes/[YOUR_DRIVE_NAME_HERE]"
https://www.youtube.com/watch?v=_VwHGSHSnDk
@bondarewicz
bondarewicz / gist:9054365
Created February 17, 2014 16:51
knapsack php
<?php
#########################################################
# 0-1 Knapsack Problem Solve with memoization optimize and index returns
# $w = weight of item
# $v = value of item
# $i = index
# $aW = Available Weight
# $m = Memo items array
# PHP Translation from Python, Memoization,
<?php
// http://en.wikipedia.org/wiki/Knapsack_problem
// http://upload.wikimedia.org/wikipedia/commons/c/c6/Knapsack_greedy.svg
// KNAPSACK BALANCER!
class Balancer
{
public static function balance($items, $key)
{
@bondarewicz
bondarewicz / gist:8843037
Created February 6, 2014 12:15
JS: Array even numbers filter
var arr = [4,5,7,8,14,45,76];
function even(a){
return a.filter(function(val){return val%2===0})
}
alert(even(arr));
@bondarewicz
bondarewicz / gist:8841713
Last active January 22, 2021 11:54
JS: Simple Like function
function likes(names) {
names[0] = names[0] || "no one";
if (names.length > 3) names[2] = names.length-2 + " others";
return names.slice(0,3).join(", ").replace(/(.*), /, "$1 and ") + " like" + (names.length<2 ? "s" : "") + " this";
}
alert(likes([])); // must return "no one likes this"
alert(likes(['Peter'])); // must return "Peter likes this"
alert(likes(['Jacob', 'Alex'])); // must return "Jacob and Alex like this"
@bondarewicz
bondarewicz / gist:8595674
Last active January 4, 2016 08:29
SQL: Explode address text column into separate columns
select
length(replace(address_str, '\r\n', '\r\n ')) - length(address_str) as AddressLineCount,
substring_index(substring_index(address_str,'\r\n',1),'\r\n',-1) as AddressLine1,
substring_index(substring_index(address_str,'\r\n',2),'\r\n',-1) as AddressLine2,
substring_index(substring_index(address_str,'\r\n',3),'\r\n',-1) as AddressLine3
from (
select replace(concat(address,'\r\n'),'\r\n\r\n','\r\n') as address_str
from table_location where location_id = 1
) normalized