Skip to content

Instantly share code, notes, and snippets.

View JohannesFischer's full-sized avatar

Johannes Fischer JohannesFischer

View GitHub Profile
"use strict"
topOfElement = (element) ->
if element then element.offsetTop + topOfElement(element.offsetParent) else 0
ScrollList = React.createClass
getDefaultProps: ->
cssclass: ''
limit: 10
offset: 150
## Data Service
myApp.provider 'dataService', ->
data =
content: []
currentIndex: -1
error: false
filter: 'list'
infiniteBusy: false
loading: false
"use strict"
ImageLoader = React.createClass
displayName: 'ImageLoader'
propTypes:
altSrc: React.PropTypes.string
attributes: React.PropTypes.object
className: React.PropTypes.string
onError: React.PropTypes.func
@JohannesFischer
JohannesFischer / ng-controller.js
Last active October 6, 2015 02:18
AngularJS - extend controller
angular.module('MyApp').controller('MyController', ['$scope', function ($scope) {
$scope.data = [1, 2, 3];
$scope.action = function () {
console.log('surprise motherfucker!');
};
}]);
angular.module('MyApp').controller('MyControllerImpl', ['$scope', '$controller',
function ($scope, $controller) {
@JohannesFischer
JohannesFischer / animations.css
Last active December 10, 2015 01:58
collection of keyframe animations
@keyframes bounceIn {
from, 20%, 40%, 60%, 80%, 100% {
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
transform: scale3d(.3, .3, .3);
}
20% {
transform: scale3d(1.1, 1.1, 1.1);
@JohannesFischer
JohannesFischer / average.php
Created February 18, 2016 10:33
Average color
<?php
$filename = 'IMAGE_PATH';
$image = imagecreatefromjpeg($filename);
$width = imagesx($image);
$height = imagesy($image);
$pixel = imagecreatetruecolor(1, 1);
imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);
$rgb = imagecolorat($pixel, 0, 0);
$color = imagecolorsforindex($pixel, $rgb);
?>
@JohannesFischer
JohannesFischer / localstorage-poly.js
Last active February 19, 2016 08:24
localStorage polyfill (non persistent)
try {
window.localStorage.setItem('testKey', '1');
window.localStorage.removeItem('testKey');
}
catch (error) {
window.localStorage = {
_data: {},
setItem: function(id, val) { return this._data[id] = String(val); },
getItem: function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
removeItem: function(id) { return delete this._data[id]; },
@JohannesFischer
JohannesFischer / .gitignore
Created February 26, 2016 06:51
my default gitignore file
# Packages
*.xpi
*.zip
# Logs and databases
*.log
*.sql
*.sqlite
# OS generated files
@JohannesFischer
JohannesFischer / post-merge
Last active June 1, 2016 00:58
Git post merge hook: Run npm install when packackage.json changed
#/usr/bin/env bash
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
@JohannesFischer
JohannesFischer / compression.rb
Last active June 11, 2016 21:15 — forked from remino/compression.rb
Ruby on Rails: Minify HTML, CSS, & JS
# config/initializers/compression.rb
Rails.application.configure do
# Use environment names or environment variables:
# break unless Rails.env.production?
break unless ENV['ENABLE_COMPRESSION'] == '1'
# Strip all comments from JavaScript files, even copyright notices.
# By doing so, you are legally required to acknowledge
# the use of the software somewhere in your Web site or app: