Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar
🚀
Lightspeed

CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@CMCDragonkai
CMCDragonkai / Git CLI Recipes.md
Last active May 24, 2024 10:24
Git CLI Recipes #git

Git Recipes

Bring in a Remote Branch

git fetch <remote>
git checkout -b <branch> --track <remote>/<branch>
@CMCDragonkai
CMCDragonkai / python2&3coexisting.md
Last active January 4, 2016 08:09
CONFIGURATION: Windows: Python 2 & 3 coexisting

Python 2 and 3

When installing Python 2 and Python 3 on a Windows computer. The environment variables determine which one to use.

So one of the python executables may be on the PATH. You can rename the python executable such as python27.exe or python33.exe.

Then you can execute them like python27 or python33 on the CLI.

However when Python launches it utilises certain environment variables to get its dependencies.

@CMCDragonkai
CMCDragonkai / PHPBrew Configuration
Last active February 18, 2022 00:24
CONFIGURATION: PHPBrew Configuration
Build PHP with PHPBrew
WORK IN PROGRESS
http://devkardia.com/easyblog/ubuntu-12-04-multiple-php-versions-and-virtualmin-using-phpbrew.html
Use these php.ini files
- Make sure to use TCP sockets for everything. Unix Domain Sockets are BAAAAD!
- Set session save path to the temporary directory
@CMCDragonkai
CMCDragonkai / sed-simple.sh
Last active August 23, 2022 05:32
BASH: Sed Simple Literal Text Search & Replace (does not support new lines)
function sed-keyword-escape {
echo $1 | sed -e 's/[]\/$*.^|[]/\\&/g'
}
function sed-replace-escape {
echo $1 | sed -e 's/[\/&]/\\&/g'
}
function sed-easy {
sed -i "s/$(sed-keyword-escape $1)/$(sed-replace-escape $2)/g" $3
@CMCDragonkai
CMCDragonkai / bisecting_binary_search.php
Last active April 2, 2023 01:57
PHP: Bisect Left & Bisect Right using Binary Search (similar to Python's bisect_left & bisect_right). Binary search only works on sorted arrays. Arrays must be first sorted with quick sort. Bisect right finds the index of a value where all the elements from left to right up to the index is less or equal to the value: Array: [1, 1, 2, 2, 3, 4] Va…
<?php
// sorted array must be a 0 indexed
// left most index, right most index all inclusive
// finds all of the elements coming from the left to the right that is less or equal to the key
function bisect_right($sorted_array, $key, $left = null, $right = null){
if(is_null($left)){
reset($sorted_array);
$left = key($sorted_array);
@CMCDragonkai
CMCDragonkai / dynamic_fibonnaci.php
Created October 27, 2014 09:07
PHP: Dynamic Fibonnaci O(n)
<?php
// O(n) time complexity with constant space complexity
function fibonacci_dynamic($n){
if($n == 0){
return 0;
}elseif($n == 1 OR $n == 2){
return 1;
}
@CMCDragonkai
CMCDragonkai / dynamic_fibonnaci.nix
Created October 27, 2014 09:08
Nix: Dynamic Fibonnaci in Functional Style O(n)
let
fib = number: fib' number 1 1;
fib' = number: first: second:
if number == 0
then first
else fib' (number - 1) second (first + second);
# the second becomes the new first, the (first + second) becomes the new second
in
fib 5
@CMCDragonkai
CMCDragonkai / dynamic_factorial.exs
Last active December 27, 2017 06:01
Elixir: Tail Recursive Factorial - Avoids growing stack space linearly. This is related to dynamic programming: http://stackoverflow.com/q/12649970/582917
// factorial tail recursive (Elixir style)
// 4! means 1*2*3*4, we can ignore 1, which makes it 2*3*4 = 24
def factorial(number) do
factorial(number, 1)
end
def factorial(number, product) do
factorial(number - 1, product * number)
@CMCDragonkai
CMCDragonkai / cumulative_slice.php
Last active June 1, 2018 20:32
PHP: Cumulative/Prefix Summing. Use these functions to sum up a numeric array for subsequent processing.
<?php
// count inclusive from x to y keys (x and y keys are the keys for the prefix sum, not the keys of the original array)
function cumulative_slice($prefix, $x, $y){
return $prefix[$y] - $prefix[$x];
}
// here's a more flexible function:
// run with X, Y when using original array indexes
// run with X, null, Z when using cumulative array indexes