Skip to content

Instantly share code, notes, and snippets.

@angusdev
angusdev / join.js
Created June 13, 2014 01:36
Oneliner to create comma separated string from array
[1,2,3].join(',').replace(/\s*,\s*(,\s*)+/g, ',').replace(/^\s*,?/, '').replace(/,?\s*$/, '').replace(/,/g, ', ')
// "1, 2, 3"
[].join(',').replace(/\s*,\s*(,\s*)+/g, ',').replace(/^\s*,?/, '').replace(/,?\s*$/, '').replace(/,/g, ', ')
// ""
[null, 2, null].join(',').replace(/\s*,\s*(,\s*)+/g, ',').replace(/^\s*,?/, '').replace(/,?\s*$/, '').replace(/,/g, ', ')
// "2"
[1, 2, null].join(',').replace(/\s*,\s*(,\s*)+/g, ',').replace(/^\s*,?/, '').replace(/,?\s*$/, '').replace(/,/g, ', ')
// "1, 2"
[null, null, null].join(',').replace(/\s*,\s*(,\s*)+/g, ',').replace(/^\s*,?/, '').replace(/,?\s*$/, '').replace(/,/g, ', ')
// ""
@REM Copy foo.txt to foo.20141218.txt
@REM Assuming Window's date format is Mon 12/18/2014
@set FROMFILE=foo.txt
@setlocal
@echo off
FOR /D %%f in (%FROMFILE%) do (
set TOFILE=%%~nf.%date:~10,4%%date:~4,2%%date:~7,2%%%~xf
@angusdev
angusdev / pdftkc.sh
Last active February 12, 2023 12:45
Command line for frequently used pdftk command
#/bin/sh
# Command line for frequently used pdftk command
# Copyright 2014-2023 ellab.org
f2=$(basename "$2")
e2="${f2##*.}"
f2="${f2%.*}"
f3=$(basename "$3")
e3="${f3##*.}"
@angusdev
angusdev / check-email.sql
Created December 29, 2014 01:55
Check validity of email address
SELECT *
FROM EMAIL_TO_CHECK ETC
WHERE ETC.EMAIL IS NOT NULL AND ETC.EMAIL <> 'NA' AND ETC.EMAIL <> 'N/A'
AND ( ETC.EMAIL IS NULL
OR ETC.EMAIL NOT LIKE '%@%'
OR ETC.EMAIL LIKE '%@%\_%' ESCAPE '\'
OR ETC.EMAIL LIKE '%.'
OR LOWER (ETC.EMAIL) LIKE '%@%.co'
OR LOWER (ETC.EMAIL) LIKE '%@%.co.hk'
OR LOWER (ETC.EMAIL) LIKE '%@%.co.mo'
πŸ˜„ πŸ˜ƒ πŸ˜€ 😊 πŸ˜‰ 😍 😘 😚 πŸ˜— πŸ˜™ 😜 😝 πŸ˜› 😳 😁 πŸ˜” 😌 πŸ˜’ 😞 😣 😒 πŸ˜‚ 😭 πŸ˜ͺ πŸ˜₯ 😰 πŸ˜… πŸ˜“ 😩 😫 😨 😱 😠
@angusdev
angusdev / ReadDataFromFiles.vbs
Last active August 29, 2015 14:14
Excel Macro to read cell values of all Excel files in a folder
Option Explicit
' Excel Macro to read cell values of all Excel files in a folder
' (c) ellab.org 2015
' http://ellab.org
' @angusdev
'
' |--------------------------------------------------------------|
' | File Name | File Path | Success? | 'Sheet1'!A1 | 'Sheet2'!B4 |
' |--------------------------------------------------------------|
@angusdev
angusdev / Cyfe-Push-CSV.md
Last active March 19, 2017 02:05
Push CSV data to Cyfe in command line
@angusdev
angusdev / find-each-in-file.sh
Created February 24, 2015 10:04
# Find the number of occurrence of each line of file in all files from current directory
# Find the number of occurrence of each line in /path/to/file in all files from current directory
# sample ouput
# alice 0
# bob 3
# chris 14
cat /path/to/file | while read -r line ; do
echo $line `grep -src $line * | grep -v ':0$' | wc -l`
done
@angusdev
angusdev / zip-each-file.sh
Created November 20, 2015 08:20
Bash command line to zip each file separately
for i in *.log; do zip "${i%/}.zip" "$i"; done
@angusdev
angusdev / qlik-map-cities.txt
Created December 1, 2015 01:43
Major Cities GeoPoint for QlikSense
MapPoint:
Load City, Latitude, Longitude, GeoMakePoint(Latitude, Longitude) As GeoPoint Inline [
City, Latitude, Longitude
'!Hong Kong', 22.2783, 114.1747
'Macau', 22.1667, 113.5500
'Mississauga', 43.6000, -79.6500
'Burnaby', 49.2667, -122.9667
// US & Canada http://www.infoplease.com/ipa/A0001796.html
'Albany', 42.66667, -73.75
'Albuquerque', 35.08333, -106.65