Skip to content

Instantly share code, notes, and snippets.

var productsBottomOffset = $('#products-end')[0].getBoundingClientRect().top - document.body.getBoundingClientRect().top;
//var productsBottomOffset = $('#products-end').offset().top;
//var productsBottomOffset = $('#products-end').position().top;
// jquery offset and position works unreliable. can't figure why for desktop position() is correct but for mobile offset()
@magemore
magemore / CodeIgniter.php
Last active November 10, 2016 15:07
code igniter 1.x 2.x mix hack to make php unit work
system/codeIgniter/CodeIgniter.php
hack inside CodeIgniter.php
after controller call just return to test without destructors and etc
<?php
call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
if (defined('UnitTest')) return;
@magemore
magemore / magento2_create_product_programmatically.php
Created October 8, 2016 00:17
magento 2 create product programmatically
<?php
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
@magemore
magemore / inject id to find location
Created August 11, 2016 08:23
problem was to find location of template in magento 2. so injected unique id to all script tags with type="text/x-magento-init"
<?php
function inject($file) {
echo $file."\n";
$pattern = 'type="text/x-magento-init"';
$patternNew = 'type="text/x-magento-init" lovethis="'.md5($file).'"';
$s = file_get_contents($file);
$s = str_replace($pattern,$patternNew,$s);
file_put_contents($file, $s);
@magemore
magemore / example.js
Created August 10, 2016 10:13
upload image from clipboard on ctrl+v event on page
function uploadFile(file) {
var formData = new FormData();
formData.append("userfile", file);
var request = new XMLHttpRequest();
request.onload = function () {
if (request.status == 200) {
document.location.href='/';
} else {
alert('Error! Upload failed');
}
@magemore
magemore / twitter.com_push_service_worker.coffee
Created July 30, 2016 11:24
kinda pretty but still cryptic
((t, n, r) ->
i = typeof require == 'function' and require
s = (o, u) ->
if !n[o]
if !t[o]
a = typeof require == 'function' and require
if !u and a
return a(o, !0)
if i
@magemore
magemore / Autohotkey
Created July 30, 2016 03:56
Autohotkey use to automate editing even in notepad
CTRL+D in Notepad++ just means "Duplicate current line".
I don't believe there's an equivalent in DW.
Perhaps use Autohotkey (or alike) to create a macro that moves to the start of the line, then selects to the end of the line, then inserts a blank line below, and then inserts your copied line:
Then bind that to CTRL+D (or whatever).
@magemore
magemore / .bashrc
Created July 26, 2016 16:28
bashrc shortcuts to cd into existing directory or find list and cd by it's number by c1 c2 c3
cdandclear_search() {
if [[ -n $7 ]]; then
find . -maxdepth $MAXDEPTH -type d | grep -i $1 | grep -i $2 | grep -i $3 | grep -i $4 | grep -i $5 | grep -i $6 | grep -i $7 | tee /tmp/cdfind | egrep -i "$1|$2|$3|$4|$5|$6|$7"
elif [[ -n $6 ]]; then
find . -maxdepth $MAXDEPTH -type d | grep -i $1 | grep -i $2 | grep -i $3 | grep -i $4 | grep -i $5 | grep -i $6 | tee /tmp/cdfind | egrep -i "$1|$2|$3|$4|$5|$6"
elif [[ -n $5 ]]; then
find . -maxdepth $MAXDEPTH -type d | grep -i $1 | grep -i $2 | grep -i $3 | grep -i $4 | grep -i $5 | tee /tmp/cdfind | egrep -i "$1|$2|$3|$4|$5"
elif [[ -n $4 ]]; then
find . -maxdepth $MAXDEPTH -type d | grep -i $1 | grep -i $2 | grep -i $3 | grep -i $4 | tee /tmp/cdfind | egrep -i "$1|$2|$3|$4"
elif [[ -n $3 ]]; then
mgvg() {
a='$a'
ag='ag -l'
xa='xargs -d "\n"'
xai='xargs -d "\n" -I{}'
dollar='$'
n='"\n"';
q="\'"
wq='"'
zero='0'
mgv() {
a='$a'
ag='ag -l'
xa='xargs -d "\n"'
n='"\n"';
q="\'"
p="$a=explode(' ','$@'); \
echo '$ag '.implode(' | $xa $ag ',$a).$n; \
echo ' | $xa ag $q'.implode('|',$a).'$q';"
#echo $p