Skip to content

Instantly share code, notes, and snippets.

View gitfvb's full-sized avatar

Florian von Bracht gitfvb

View GitHub Profile
@gitfvb
gitfvb / array_addons.js
Created October 10, 2015 14:34
Get the size of javascript associative arrays
// get the size of associative arrays
$.assocArraySize = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
@gitfvb
gitfvb / responsive.js
Last active October 10, 2015 14:50
Resize the fixed width of html elements to allow responsive design for e.g. d3 visualisations
/*
description:
This function allows you to resize an html element
when the screen size is changing (resize the browser or ).
This allows you responsive design on some elements with
fixed pixel sizes. This can be used e.g. for d3.js visualisations.
author: Florian von Bracht
email: f@dataflo.de
@gitfvb
gitfvb / remove_n_entries.js
Created October 19, 2015 11:45
remove the 1000 first entries of the mongodb collection 'foo' by id
// count all the records first
db.getCollection('foo').find({}).count();
// save the the first 1000 entries ids to an array
removeIdsArray = db.getCollection('foo').find({})
.limit(1000)
.toArray()
.map(function(doc) { return doc._id; });
@gitfvb
gitfvb / customers.sql
Created October 21, 2015 17:26
MySQL Statement for customers on magento including first name, last name and birthday
SELECT
e.entity_id
,e.email
,e.group_id
,e.store_id
,e.created_at
,e.updated_at
,e.is_active
,at_birthday.value as birthday
,at_firstname.value AS firstname
@gitfvb
gitfvb / json2json_with_url.js
Created October 30, 2015 00:00
use node.js to load JSON content from a url and then reformat it
//Load the request module
var request = require('request');
var content = request('<url with json content>', function (error, response, body) {
if (!error && response.statusCode == 200) {
//console.log(body); // Show the HTML for the Modulus homepage.
//console.log(util.inspect(body, {showHidden: false, depth: null})); // show the full content
// load the modules
var bbj2j = require('jsonapter');
@gitfvb
gitfvb / exiftool.ps1
Last active June 5, 2022 14:00
use exiftool to move photos and videos in a subfolder structure like 2016/201612/
$exiftool = "C:\Users\Florian\Pictures\exiftool(-k).exe"
$source = "C:\Users\Florian\Pictures\k-r\DCIM1"
$destination = "C:\Users\Florian\Pictures\k-r\sorted"
$timestamp = [datetime]::UtcNow.ToString("yyyyMMddHHmmss")
$logfile = "copymedia_date$( $timestamp ).log"
<#
source: https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
-ext only files with this extension
@gitfvb
gitfvb / attach_multiple_databases_from_designer.md
Last active September 9, 2020 09:31
code snippets for sqlite

This statement in a single query (e.g. in FastStats Designer) can attach other databases to the current one attach database C:\Apteco\Build\system\data\lookups.sqlite as lookup The ATTACH is not persistent in Designer

ATTACH DATABASE "C:\Apteco\Build\system\data\lookups.sqlite" AS lookup;
SELECT g.*, p.*
FROM geschaeftspartner g
INNER JOIN lookup.plz5 p ON g.plz = p.plz limit 10;
@gitfvb
gitfvb / update_dyndns.ps1
Last active April 7, 2016 10:44
Update DynDNS via powershell (in this case strato). Replace the variables {host}, {username} and {password}. Also change your DynDNS-provider.
$ExtIPv4 = Get-NetIpAddress -InterfaceAlias "Ethernet 2" -AddressFamily "IPv4"
$source = "https://dyndns.strato.com/nic/update?hostname={host}&myip=$($ExtIPv4.IPAddress)"
$user = "{username}"
$pass = "{password}"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
Invoke-WebRequest -Uri $source -Credential $credential
@gitfvb
gitfvb / Rprofile.site
Created January 24, 2017 08:53
Load scripts into R at startup (especially needed for Rserve) - overwrite file in etc/
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
@gitfvb
gitfvb / geocode.ps1
Created January 24, 2017 09:01
GeoCoding with OSM, Bing and Google through the PowerShell - no addon needed
# https://msdn.microsoft.com/en-us/library/dn894107.aspx
<#
.Synopsis
This function uses the Google Maps API to Geocode an address.
.DESCRIPTION
This function uses the Google Maps API to Geocode an address by sending a web request to the API and then processes the resulting XML file for the longitude & latitude. The Google API has a threshold and when violated, you get an OVER_QUERY_LIMIT error based on the number of calls made per second and per day. If the function encounters this error it will pause for 2 seconds and throw a warning. If two subsequent calls fail, then the daily max call may have been reached and it will error out.
.EXAMPLE
PS C:\> "7171 Southwest Parkway, Austin, TX" | Get-GeoCode