Skip to content

Instantly share code, notes, and snippets.

View kbshl's full-sized avatar

Konstantin Büschel kbshl

  • Marburg, Hessen, Deutschland
  • 04:01 (UTC +02:00)
  • X @iskostja
View GitHub Profile
@kbshl
kbshl / convert.js
Created October 15, 2014 11:23
Convert HTML Links to Titanium Mobile App Links that fire Ti.App.Events
var convertedHTML = htmlString;
// event-handler for app
convertedHTML = htmlString.replace(/<a href="((http|https)[^"]+)"[^>]*>(.*?)<\/a>/gmi, '<a href="$1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {link: \'$1\'}); return false;">$3</a>');
// mailto special
convertedHTML = convertedHTML.replace(/<a href="mailto:([^"]+)"[^>]*>(.*?)<\/a>/gmi, '<a href="mailto:$1" onclick="Ti.App.fireEvent(\'app:webViewClick\', {linkType: \'email\', link: \'$1\'}); return false;">$2</a>');
@kbshl
kbshl / multipleSourcesOneTaskGulp.js
Created September 16, 2014 15:09
Gulp Receipe: Using multiple sources in one task
// npm install --save-dev gulp merge-stream
var gulp = require('gulp');
var merge = require('merge-stream');
gulp.task('test', function() {
var bootstrap = gulp.src('bootstrap/js/*.js')
.pipe(gulp.dest('public/bootstrap'));
var jquery = gulp.src('jquery.cookie/jquery.cookie.js')
@kbshl
kbshl / config.json
Created September 16, 2014 15:08
Gulp Receipe: Using external config file
{
"desktop" : {
"src" : [
"dev/desktop/js/**/*.js",
"!dev/desktop/js/vendor/**"
],
"dest" : "build/desktop/js"
},
"mobile" : {
"src" : [
@kbshl
kbshl / taskDependencyGulp.js
Created September 16, 2014 15:07
Gulp Receipe: Running tasks in series, i.e. Task Dependency
/*
By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. If you want to create a series where tasks run in a particular order, you need to do two things:
give it a hint to tell it when the task is done,
and give it a hint that a task depends on completion of another.
For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:
In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're done or return a promise or stream that the engine should wait to resolve or end respectively.
In task "two" you add a hint telling the engine that it depends on completion of the first task.
@kbshl
kbshl / filePerFolderGulp.js
Created September 16, 2014 15:06
Gulp Receipe: Generating a file per folder
/*
If you have a set of folders, and wish to perform a set of tasks on each, for instance...
/scripts
/scripts/jquery/*.js
/scripts/angularjs/*.js
...and want to end up with...
/scripts
/scripts/jquery.min.js
@kbshl
kbshl / onlyChangedFilesGulp.js
Created September 16, 2014 15:05
Gulp Receipe: Rebuild only files that change
// With gulp-watch:
var gulp = require('gulp');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
gulp.task('default', function() {
return gulp.src('sass/*.scss')
.pipe(watch())
.pipe(sass())
@kbshl
kbshl / cliArgsGulp.js
Created September 16, 2014 15:04
Gulp Receipe: Pass arguments from the command line
// npm install --save-dev gulp gulp-if gulp-uglify minimist
var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var minimist = require('minimist');
var knownOptions = {
string: 'env',
@kbshl
kbshl / changedFilesGulp.js
Created September 16, 2014 15:04
Gulp Receipe: Only pass through changed files
// Files are passed through the whole pipe chain on every run by default. By using gulp-changed only changed files will be passed through. This can speed up consecutive runs considerably.
// npm install --save-dev gulp gulp-changed gulp-jscs gulp-uglify
var gulp = require('gulp');
var changed = require('gulp-changed');
var jscs = require('gulp-jscs');
var uglify = require('gulp-uglify');
// we define some constants here so they can be reused
@kbshl
kbshl / minNonMinVersionOutputGulp.js
Created September 16, 2014 15:09
Gulp Receipe: Output both a minified and non-minified version
// Outputting both a minified and non-minified version of your combined JavaScript files can be achieved by using gulp-rename and piping to dest twice (once before minifying and once after minifying):
'use strict';
var gulp = require('gulp');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var DEST = 'build/';
@kbshl
kbshl / gatekeeper.sh
Created September 18, 2014 15:40
Removing Gatekeeper flag that causes Gatekeeper to check Application
cd /Applications
xattr -d com.apple.quarantine APPNAME # e.g. Xcode6-Beta7.app