Skip to content

Instantly share code, notes, and snippets.

View kasparsj's full-sized avatar

Kaspars Jaudzems kasparsj

View GitHub Profile
@kasparsj
kasparsj / simple_form_wrappers_merge_classes.rb
Created August 25, 2017 09:02
Monkey patch for SimpleForm to be able to override bootstrap grid classes
module SimpleForm
module Wrappers
class Many
private
def wrap(input, options, content)
return content if options[namespace] == false
return if defaults[:unless_blank] && content.empty?
@kasparsj
kasparsj / include_selected_option.rb
Last active February 27, 2017 23:13
Patch for ActionView::Helpers to add 'include_selected' option to CollectionSelect, options_from_collection_for_select, options_for_select
module ActionView::Helpers
module Tags
class CollectionSelect < Base
def render
option_tags_options = {
:selected => @options.fetch(:selected) { value(@object) },
:include_selected => @options.fetch(:include_selected, false),
:disabled => @options[:disabled]
}
@kasparsj
kasparsj / backup-www.sh
Created October 23, 2015 07:06
Backup a directory, copy latest backup to S3
#!/bin/sh
DIR=`/var/www`
NAME=`www`
DATE=`date +%d%m%y%H%M`
S3_BUCKET="s3://my-bucket"
# export files
tar czf /opt/backups/${NAME}_${DATE}.tar -C / ${DIR}
cp /opt/backups/${NAME}_${DATE}.tar /opt/backups/${NAME}-latest.tar
@kasparsj
kasparsj / backup-db.sh
Created October 23, 2015 07:00
Backup all MySQL databases, copy latest backup to S3
#!/bin/sh
DB_USER="root"
DB_PW="root"
DATE=`date +%d%m%y%H%M`
S3_BUCKET="s3://my-bucket"
# export database
mysqldump -u $DB_USER -p${DB_PW} --all-databases | gzip > /opt/backups/db_${DATE}.bak.gz
cp /opt/backups/db_${DATE}.bak.gz /opt/backups/db-latest.bak.gz
@kasparsj
kasparsj / requestAnimationFrame.js
Created September 28, 2015 11:20
requestAnimationFrame polyfill
// Adapted from https://gist.github.com/paulirish/1579671 which derived from
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller.
// Fixes from Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon
// MIT license
(function() {
@kasparsj
kasparsj / CountUpTimer.java
Created April 13, 2014 19:57
An infinite timer
import android.os.CountDownTimer;
abstract public class CountUpTimer
{
private CountDownTimer countDownTimer;
private int countDownCycle;
public CountUpTimer(long countUpInterval) {
countDownTimer = new CountDownTimer(Long.MAX_VALUE, countUpInterval) {
@Override
@kasparsj
kasparsj / OneLog.java
Created April 13, 2014 19:55
android.util.Log without the tag
public class OneLog {
public static String TAG = OneLog.class.getName();
private OneLog() {
}
public static int v(String msg) {
return android.util.Log.v(TAG, msg);
}
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import com.koushikdutta.async.AsyncNetworkSocket;
import com.koushikdutta.async.AsyncServer;
import com.koushikdutta.async.AsyncServerSocket;
import com.koushikdutta.async.AsyncSocket;
import com.koushikdutta.async.ByteBufferList;