Skip to content

Instantly share code, notes, and snippets.

Thomas Fritz thomasfr

Block or report user

Report or block thomasfr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@thomasfr
thomasfr / test.js
Last active Jun 22, 2017
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
View test.js
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 Jun 14, 2017
babelrc with babel-preset-env to just compile necessary ES features for given node version. With support for flow types
View .babelrc.json
{
"presets": [
[
"env",
{
"targets": {
"node": "6.10"
}
}
],
View gist:5f9ed341fbc9ce7c43aa
$(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
View gist:fcec40e289bd40d9461a
$(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 Jul 20, 2018
duplicity.backup Bash Script with Rollbar Notification
View backup.sh
#!/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
View grunt-replace.js
options: {
patterns: [
{
src: ['assets/js/**/*.js', 'assets/css/**/*.css',],
search: /@@([^@]+?)@@/g,
replace: function(matched, part, offset, string) {
if(summary[part]) {
return summary[part];
}
else {
View test.js
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) {
View node_debian_init.sh
#!/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 Jul 20, 2018
Execute a SQL Statement in many Databases of one mysql server
View multi-exec.sh
#!/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 Sep 18, 2014
Recursively compare two directories and print which files have changed. Ignore binary files and do not show non existing files in `dir2`
View what-changed.sh
#!/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
You can’t perform that action at this time.