Skip to content

Instantly share code, notes, and snippets.

View bgadrian's full-sized avatar
✍️
available for OSS Go packages

B.G.Adrian bgadrian

✍️
available for OSS Go packages
View GitHub Profile
@bgadrian
bgadrian / build_all.sh
Created April 1, 2016 10:00
Build Soomla unity3d for iOS with bitcode
//core
//https://github.com/soomla/soomla-ios-core/blob/9c078800aa4b041bf805f432d5cbe6483adf61d7/build_all
xcodebuild -configuration Release ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" -sdk iphoneos -project SoomlaiOSCore.xcodeproj -target SoomlaiOSCore clean build CREATING_UNIVERSAL_DIR=$PWD/build
cp -r libs/keeva/ build/
//store
@bgadrian
bgadrian / autoScroll
Created April 16, 2015 13:30
Floating div, when scroll down
$(window).scroll(function () {
//TODO put a throttle here
if($(this).scrollTop() > $j('#anchor').offset().top)
{
$element.css({
position: 'fixed',
top: 0
})
} else {
@bgadrian
bgadrian / child.js
Created March 17, 2015 07:45
JS Prototype Inheritance while keeping own class name
//in console log and memory profiler, the Child name will appear instead of Master.
var Child = function(){
//call the parents construct, he knows what to do
this._construct.apply(this, arguments);
};
Child.prototype = new Master(true);//one instance of Master will always be in memory as a prototype
Child.prototype.OnInit = function(params){};
@bgadrian
bgadrian / duplicates.sql
Created March 16, 2015 17:37
MYSQL Look for duplicate rows, in the same table, by a different column (not primary or unique).
SELECT p1.id,p1.cod , p2.id,p2.cod #here we find the duplicate data from cod column, but i need the ID to show ...
FROM `st_produse` p1 #the table, first time
LEFT JOIN st_produse p2 ON p1.cod = p2.cod #the table second time
WHERE p1.id <> p2.id #here put the key or a unique column
GROUP BY p1.cod #the c
@bgadrian
bgadrian / upload.html
Created March 16, 2015 17:36
HTML post file upload
<!-- default value -->
<form method="post" enctype="application/x-www-form-urlencoded">
<!-- if you want to upload a file -->
<form method="post" enctype="multipart/form-data">
<input type="file" />
@bgadrian
bgadrian / rgb.to.hex.js
Created March 16, 2015 17:35
JS color translate css from RGB to HEX
//usage
//alert (RGB_to_HEX('rgb(119,110,200)'));
function RGB_to_HEX(RGB)
{
var parts = RGB
.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
// parts now should be ["rgb(0, 70, 255", "0", "70", "255"]
delete (parts[0]);
for (var i = 1; i <= 3; ++i) {
@bgadrian
bgadrian / example.simplexml.php
Created March 16, 2015 17:34
PHP simpleXML example modify
<?php
/* With simplexml, open an entire file (use XMLReader for big files)
Example : <root><s name="abc">value</s>....</root>*/
$xml = simplexml_load_file($xml_source_path);
//find the elemnt by attribute's value (name=..)
$result = $xml->xpath('//s[@name="'.$element_name.'"]');
//heres the trick - the first result of xpath, and the node value (stored in [0])
$result[0][0] = $new_value;
//here you can do a foreach, to cross over all results (all "s" elements with the same name"
if ($xml->asXML($xml_source_path) === false)
@bgadrian
bgadrian / cycle.loop.php
Created March 16, 2015 17:34
PHP loop template {cycle}
<?php
//btools.eu PHP function to cycle array values (smarty {cycle} replacement)
function _bCycle(&$arr)
{
$v = next($arr);
if ($v === false)
return reset($arr);
return $v;
}
$table_colors = array('white','red','yellow');
@bgadrian
bgadrian / debug.logger.php
Created March 16, 2015 17:33
PHP Simplest way to log actions
<?php
//just TEXT log any action, and info about it, like a purchase, use for backup/internal storage
//I use this for all types of requests, when dealing with online payments
/* LOG */
file_put_contents('logs/'.date('Y.m').'.pay.log','['.$_SERVER['REMOTE_ADDR'].'] '.date('Y.m.d-H:i:s').': Order ID : '.$order_id.', Error : '.$error.', Sum'.$payed_sum.', Transaction : '.$transaction_id.PHP_EOL,FILE_APPEND);
//I recommend to keep the comma, for eventual csv reading
//automatically creates a single file per month, keeping the logs small
//keeps the IP and time stamp in a nice juman form
@bgadrian
bgadrian / cross.domain.php
Created March 16, 2015 17:32
Header, for cross domain AJAX request
/in the response page
header('Access-Control-Allow-Origin : *'); //* all requests origins sites are allowed