Skip to content

Instantly share code, notes, and snippets.

View apaatsio's full-sized avatar

Antti Ahti apaatsio

View GitHub Profile
@apaatsio
apaatsio / photo.rb
Created August 1, 2011 10:02
S3 config for Paperclip
class Photo < ActiveRecord::Base
has_attached_file :image,
:styles => {
:thumb => '100x100',
:large => '640x480',
},
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => ':attachment/:id/:style.:extension',
:bucket => 'my-bucket',
@apaatsio
apaatsio / plugin.js
Created April 18, 2012 08:36
how to unit test internal functions in jquery plugin?
// Define global Test object. You can leave this out in production.
Test = Test || {};
(function($) {
var someHelperFunction = function(s, d) {
return s*d;
}
var someOtherHelperFunction = function(s) {
return s*2;
@apaatsio
apaatsio / password_generator.coffee
Last active October 11, 2015 00:38
password generating function
generatePassword = (length) ->
# similar looking characters have been removed (e.g. letter l(L) and number 1)
allowedChars = "acdefghjkmnpqrstuvwxyzCDEFGHJKLMNPQRTUVWXY3679-+?@"
password = ""
for [1..length]
password += allowedChars[Math.floor(Math.random() * allowedChars.length)]
password
@apaatsio
apaatsio / highlight_dom_elements.js
Created January 31, 2013 14:25
Highlight all DOM elements with a color so it's easy see an overview of the elements at quick glance
var elements = document.querySelectorAll('*');
Array.prototype.slice.call(elements).forEach(function (element) {
var rgba = [Math.floor(Math.random()*256), Math.floor(Math.random()*256), Math.floor(Math.random()*256), 0.1];
element.style.background = 'none';
element.style.backgroundColor = 'rgba(' + rgba.join(',') + ')';
});
@apaatsio
apaatsio / xfce4-dev-setup.sh
Last active December 17, 2015 11:39
Setup script for Xfce4 build dependencies on Ubuntu. With these you can build at least xfwm4, xfce4-appfinder, xfce4-panel, and xfce4-terminal.
#!/bin/sh
apt-get -y install gcc gtk-doc-tools libexo-1-dev libgarcon-1-0-dev libglib-2.0-dev libvte-dev libwnck-dev libxfce4ui-1-dev libxfce4util-dev xfce4-dev-tools xserver-xorg-dev
@apaatsio
apaatsio / caller.coffee
Created July 17, 2013 09:52
Load JavaScript functions synchronously just-in-time. This is just a concept. This is not ready and I haven't even tried running this.
myObject =
myFunction: loadFunction 'myModule/myFunction', this
@apaatsio
apaatsio / reaktor_fast_track.js
Last active December 22, 2015 06:58
Solution for Reaktor's programming task at http://reaktor.fi/ura/fast_track/ This solution relies on the fact that JavaScript can solve multiplication for strings (e.g. "2" * "3" -> 6) and thus parseInt is not needed.
function (input) {
function product(numbers) {
if (numbers.indexOf("0") !== -1) {
return 0
} else {
return _(numbers).reduce(function(product, number){
return product * number
}, 1)
}
}
@apaatsio
apaatsio / gulp.log
Created December 1, 2014 12:12
gulp watch ENOENT error (gulp 3.8.10)
Error: watch ENOENT
at errnoException (fs.js:1030:11)
at FSWatcher.start (fs.js:1062:11)
at Object.fs.watch (fs.js:1087:11)
at Gaze._watchDir (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:289:30)
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:358:10
at iterate (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:52:5)
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:61:11
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:420:5
at iterate (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:52:5)
@apaatsio
apaatsio / dynamodb-rest-api-lambda.js
Last active September 13, 2019 16:13
Single Lambda function for all CRUD operations with DynamoDB in REST API
console.log('Loading function');
var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
/**
* Provide an event that contains the following keys:
*
* - operation: one of the operations in the switch statement below
* - tableName: required for operations that interact with DynamoDB
@apaatsio
apaatsio / openstack_kubernetes_dev.md
Created October 3, 2016 20:35
Setting up OpenStack + Kubernetes dev environment

Instructions to setup OpenStack + Kubernetes development environment on VirtualBox

Total time for the setup is about 45 minutes but most of it is waiting packages to download and install.

  1. Download Ubuntu and install it on VirtualBox (20min)

  2. Start the Ubuntu (1min)

  3. Install git (1min)

     sudo apt install git
    
  4. Follow instructions on http://docs.openstack.org/developer/devstack/ (20min)