Skip to content

Instantly share code, notes, and snippets.

View thomasfr's full-sized avatar

Thomas Fritz thomasfr

View GitHub Profile
@thomasfr
thomasfr / test.js
Last active June 22, 2017 13:49
Example for "Extract object structure by usage". This would help refactoring an old code base where the structure of some arguments are not exactly known, or when testing and it is necessary to mock a dependency and you have to pass a object with the same structure for instance
function foo (options, meta, callback) {
console.log(options.propOne)
console.log(options.propTwo[0].foo)
console.log(options.propTwo[0].bar)
console.log(options.propThree.subProp.hello)
meta.foo = 'bar'
}
// A IDE could extract the structure of `options` as JSON
// and copy that structure into the clipboard (functionality could be found in a context menu for example)
@thomasfr
thomasfr / .babelrc.json
Created June 14, 2017 11:55
babelrc with babel-preset-env to just compile necessary ES features for given node version. With support for flow types
{
"presets": [
[
"env",
{
"targets": {
"node": "6.10"
}
}
],
$(function() {
// fileinput bei android deaktivieren
if(!navigator.userAgent.match(/Android/i)) {
$.getScript("/sites/all/themes/fragnebenan/js/fileinput.min.js", function(){
console.log('fileinput laden');
});
}
})
// oder
$(function() {
console.log('ich werde ausgeführt wenn alle DOM ready und alles geladen ist')
function triggerColLeftIcon(){
$('.col-icon-left').css({'display':'none!important'});
$('.col-icon-right').css({'display':'block!important'});
}
function triggerColRightIcon(){
$('.col-icon-right').css({'display':'none!important'});
$('.col-icon-left').css({'display':'block!important'});
}
@thomasfr
thomasfr / backup.sh
Last active January 15, 2020 17:03
duplicity.backup Bash Script with Rollbar Notification
#!/bin/bash
export FTP_PASSWORD="123456"
FTP_USER="user"
FTP_HOST="user.your-backup.de"
BACKUP_TARGET="ftp://${FTP_USER}@${FTP_HOST}/$(hostname)"
DUPLICITY_LOGFILE="/var/log/duplicity.log"
DUPLICITY_TEMPDIR="/tmp/duplicity"
# Rollbar access token
ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxx
options: {
patterns: [
{
src: ['assets/js/**/*.js', 'assets/css/**/*.css',],
search: /@@([^@]+?)@@/g,
replace: function(matched, part, offset, string) {
if(summary[part]) {
return summary[part];
}
else {
var foo = function(text, callback) {
if(text == "hello") {
callback("hello world");
console.log("Someone said hello");
}
callback("why don't you say hello?");
console.log("nobody likes me :(");
}
foo("hello", function(result) {
#!/bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@thomasfr
thomasfr / multi-exec.sh
Last active July 20, 2018 07:56
Execute a SQL Statement in many Databases of one mysql server
#!/bin/bash
user="${1}"
host="${2}"
like="${3}"
all_dbs="$(mysql -u $user -p -h "$host" -Bse 'SELECT SCHEMA_NAME from information_schema.SCHEMATA WHERE SCHEMA_NAME like "${like}"' 2> /dev/null)"
for db in $all_dbs
do
mysql -u $user -p -h "$host" $db -sN -e "SELECT * FROM centerdaten;" 2> /dev/null
@thomasfr
thomasfr / what-changed.sh
Created September 18, 2014 16:04
Recursively compare two directories and print which files have changed. Ignore binary files and do not show non existing files in `dir2`
#!/bin/bash
dir1="/tmp/dir1"
dir2="/tmp/dir2"
IFS=$'\n'
for file in $(grep -Ilsr -m 1 '.' "$dir1"); do diff -q --exclude="cache" "$file" "${file/${dir1}/${dir2}}" 2> /dev/null; done