Skip to content

Instantly share code, notes, and snippets.

View coderofsalvation's full-sized avatar

Coder of Salvation / Leon van Kammen coderofsalvation

View GitHub Profile
importing products from csv-file: executing: DROP TABLE IF EXISTS sync_products_import;
executing: CREATE TABLE IF NOT EXISTS sync_products_import ( Id varchar(255),Name varchar(255),Ptype varchar(255),Price varchar(255),Stock varchar(255),IsInStock varchar(255),Category varchar(255),SubCategory varchar(255),SearchName1 varchar(255),SearchName2 varchar(255)
);
executing: INSERT INTO sync_products_import (Id,Name,Ptype,Price,Stock,IsInStock,Category,SubCategory,SearchName1,SearchName2) VALUES ('398','','simple','39.2','165890','0','Overige','Kegels/Kogels/Naalden','6.35BNZ','6,35MM BRONZE');
.OK
OK
comparing products executing: SELECT * FROM sync_products_magento as a, sync_products_import as b where a.Id = b.Id AND ( a.Stock != b.Stock )
1 updates found
updating products .SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`admin_ibs`.`catalog_product_entity`, CONSTRAINT `FK_CAT_PRD_ENTT
@coderofsalvation
coderofsalvation / getopts.tpl.bash
Last active August 29, 2015 13:56
snippet for getopts to easily support options and arguments in your shellscript
# snippet for getopts to easily support options and arguments in your shellscript
# usage: copy/paste it and run ./yourcommand -h foofoo -n barbar one two
# initialize variables
OPTION1="foo"
OPTION2="bar"
OPTIONS=0
# get rid of appname and (parse) options
shift
while getopts ":h:n:" opt
@coderofsalvation
coderofsalvation / debug.cache.js
Created February 8, 2014 09:03
html5 offline cache debugsnippet
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
@coderofsalvation
coderofsalvation / debug_http.bash
Last active August 29, 2015 13:56
shows statistics for an url like requesttime e.g.
# shows statistics for an url like requesttime e.g.
# usage: debug_http "http://foo.com/bar"
# @dependancy: curl
debug_url () {
curl -s $@ -o /dev/null \
-w "http_code %{http_code} time_appconnect %{time_appconnect} time_namelookup %{time_namelookup} time_connect %{time_connect} time_pretransfer %{time_pretransfer} time_starttransfer %{time_starttransfer} time_total %{time_total} speed_download %{speed_download}\n"
}
@coderofsalvation
coderofsalvation / iptools.bash
Last active August 29, 2015 13:56
ip functions (check whether ip is in given range e.g.)
# ip functions (check whether ip is in given range e.g.)
# collected from https://github.com/caquino/bash-functions/blob/master/network-lib
iscidr () {
[[ ${1} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/?[0-9]{1,2}?$ ]] && echo $1
}
inet_ntoa () {
[[ ${1} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] || return 255
@coderofsalvation
coderofsalvation / urlencode.bash
Created February 14, 2014 08:35
applies a raw url encode on the string
# applies a raw url encode on the string
# usage: urlencode "foo foo bar" <-- outputs: foo%3dfoo%20bar
# @param string stringtoencode
urlencode() {
local string="${1}"; local strlen=${#string}; local encoded=""
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
@coderofsalvation
coderofsalvation / args2http.bash
Last active August 29, 2015 13:56
converts commandline arguments 'one --flag "123 4"' e.g. to a http get-string '?1=one&flag=123%204'
# converts commandline arguments to a http get-string
# usage: args2http one --flag 123 two --somekey somevalue <-- outputs: ?1=one&flag=123&2=two&somekey=somevalue
/ /bash/function/string/urlencode!
args2http(){
httpstr="?"; pos=1; lastarg=""
for arg in "$@"; do
if [[ "${arg:0:1}" == "-" ]]; then
key="${arg//-/}"; httpstr="$httpstr&$key="; lastarg="option"
@coderofsalvation
coderofsalvation / calculate.bash
Created February 17, 2014 22:41
simple calculation function for integer *and* floating point math
# simple calculation function for integer *and* floating point math
#
# @param string to be calculated
# @param precision (default = 0)
# usage: calculate "(1+1)/2/10" <- outputs 0
# calculate "(1+1)/2/10" 10 <- outputs 0.1
# echo $(calculate "1+1") <- outputs 2
calculate(){
if [[ -n "$2" ]]; then
@coderofsalvation
coderofsalvation / lines_to_csv.bash
Created February 21, 2014 21:19
transforms every x number of lines to one commaseperated line
# merges x number of lines to one commaseperated line
# usage: echo -e "jan\ncold\nrain\njune\nhot\dry\n" | lines_to_csv ',' 'a,b,c'
# will output:
# "jan","cold","rain"
# "june","hot","dry"
lines_to_csv(){
lines="$(cat -)"; delimiter="$1"; columns="$2";
outputline=""
ncolumns="$( echo "$columns" | grep -o "$delimiter" | wc -l)";
@coderofsalvation
coderofsalvation / striphtml.bash
Created March 1, 2014 01:12
strip html/xml tags from input string
# strip html/xml tags from input string
# usage: echo "<b>foo</b>" | striphtml <-- returns 'foo'
striphtml(){
echo "$1" | sed 's|<[^>]*>||g'
}