Category: snippets

  • BigQuery Bulk Insert using Python

    To insert multiple rows at once using DML in BigQuery, you can do something like this: The above snippet inserts multiple rows into the table (table with columns: id and createdAt) in one go. You can also see that values types are being supplied (id:STRING and createdAt:TIMESTAMP). Binding the values this way (using parameters) will…

  • Row to Column in MySQL

    Say you have two tables like these: And you have these values: id name 1 Kesavan 2 Madhavan user_id attribute_name attribute_value 1 GENDER M 1 PREMIUM_USER N 1 SUBSCRIBED_TO_NEWSLETTER Y 2 GENDER M 2 PREMIUM_USER Y To get a result like this: id name GENDER PREMIUM_USER SUBSCRIBED_TO_NEWSLETTER 1 Kesavan M N Y 2 Madhavan M…

  • PHP openssl_encrypt tip

    Recently I had to encrypt some data in PHP and send it to a Java App, the Java app was unable to decrypt the message. I experimented with (data) padding, changing ciphers and changing the options for openssl_encrypt, but, none of those worked. It was a requirement at the Java end for the Key to…

  • Using Generators to flatten a JSON doc in PHP

    To flatten a JSON like this: to: I used the following code:

  • Jenkins parallel pipeline

    I was very excited to know about the ‘parallel’ feature in Jenkins Pipeline, but, there are many gotchas while making  use of the pipeline feature (many of which are documented here: Jenkins Pipeline Example). After trying and reading a few different solutions, following worked for me (notice in screenshot that the browser jobs run in…

  • darker background image

    I was stunned to learn I could set the opacity of a background image like this: background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url(‘/path/to/image’); and darken the background image.

  • casperjs output to html

    Documenting what I had to do. Used XSLT from here: nosetest xslt Problems and Fixes: Firefox was inserting “transformiix” as the root element, this caused the DOCTYPE to be spit out. I fixed by adding: doctype-public=”-//W3C//DTD HTML 4.0//EN”/ to

  • Checking for the existence of domains from commandline in Bash

    while read line; do wget –quiet –spider –timeout=10 $line; if [ $? -ne 0 ]; then echo $line; fi; done < "/tmp/domains.txt" /tmp/domains.txt would hold the list of domain names separated by newline. Note this is just a quick hack and not entirely reliable.

  • PHP as a replacement for sed/awk

    I had gotten sick of not being able to do what I wanted to do with sed/awk – partly because I am not too familiar with those – and, was investigating replacements for those. Many people seem to be using perl and since I wasn’t too familiar with Perl as well, I started thinking about…

  • Regular Expression to check for comma separated list of Integers

    //get rid of all kinds of spaces $IDs = preg_replace(‘/s+/’, ”, $inputIDs); if(!preg_match(”/^\d+$|^(\d+,)+\d+$/”, $IDs)) { echo “Invalid Input”; } You could use the validated IDs above in a SQL like the this: SELECT * FROM t1 WHERE id IN($IDs) Disclaimer: I am not going to be responsible for any kind of SQL injection resulting from…