Skip to content

Instantly share code, notes, and snippets.

View s22su's full-sized avatar
🎮
Focusing

Sergei Beregov s22su

🎮
Focusing
View GitHub Profile
@s22su
s22su / fix-kb-show-hide.js
Created August 16, 2013 08:35
iPad keyboard show/hide position fix
//http://stackoverflow.com/questions/2593139/ipad-web-app-detect-virtual-keyboard-using-javascript-in-safari
var currentscroll = 0;
$('input').bind('focus',function() {
currentscroll = $(window).scrollTop();
});
$('input').bind('blur',function() {
if(currentscroll != $(window).scrollTop()){
$(window).scrollTop(currentscroll);
@s22su
s22su / gist:6424074
Created September 3, 2013 13:40
Drupal7 check if node is in edit mode
if(arg(0) == 'node' && arg(2) == 'edit'){ /*...*/}
@s22su
s22su / gist:6608836
Created September 18, 2013 13:01
Create android dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Content").setTitle("Title");
AlertDialog dialog = builder.create();
dialog.show();
@s22su
s22su / gist:7413000
Created November 11, 2013 13:13
Magento - change all simple products visibility
// Get all simple products
$simples = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE));
// Get their ids
$ids = array();
foreach ($simples as $simple) {
$ids[] = $simple->getId();
}
@s22su
s22su / paramcheckforfalse.js
Last active December 31, 2015 00:19
Check if JS object contains key
_.each(someObject, function(item, key) {
if(!(key in someOtherObject)) {
// do something here
}
});
@s22su
s22su / gist:9641524
Last active August 29, 2015 13:57
In memoriam of magento
<?php
// Fugly hack, because apparently displaying prices requires a degree in rocket surgery
// replaced with normal code
$products = $_product->getTypeInstance()->getAssociatedProducts();
$min = 999999999;
foreach ($products as $product){
$price = $product->getPrice();
if ($price < $min)
$min = $price;
}
@s22su
s22su / magento-filter-by-attribute.php
Last active August 29, 2015 13:57
Magento: filter product collection by arrtibute containing some id..
<?php
// this is my custom function that gets ID of currently selected bike make
$selectedMake = getSelectedMake();
// now I am filtering
// I need to get only the products that have this make, but one product may have many different makes
// so if it has many makes, it is an array and we need to use 'finset' like so
if($selectedMake !== null) {
$productCollection->addAttributeToFilter(array(
<?php
/**
* Checks given coordinate for errors
* @param string $coordinate coordinate
*
* @return bool result
*/
public function checkCoordinate($coordinate) {
if(preg_match('/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?);[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/', $coordinate)) {
return true;

How to share a folder with a docker container on OSX

Mounting shared folders between OSX and the docker container is tricky due to the intermediate boot2docker VM. You can't use the usual docker -v option as the docker server knows nothing about the OSX filesystem - it can only mount folders from the boot2docker filesystem. Fortunately, you can work around this using SSHFS.

@s22su
s22su / arrUnique.js
Created July 30, 2014 12:50
Array unique values finder
/**
* filter array and keep every value only once
* @param array arr input array
*
* @return array array containing only unique values
*/
function arrUnique(arr) {
arr = arr.filter(function (val, i, self) {
return self.indexOf(val) === i;
});