Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaspars Jaudzems kasparsj

View GitHub Profile
@kasparsj
kasparsj / simple_form_wrappers_merge_classes.rb
Created Aug 25, 2017
Monkey patch for SimpleForm to be able to override bootstrap grid classes
View simple_form_wrappers_merge_classes.rb
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 Feb 27, 2017
Patch for ActionView::Helpers to add 'include_selected' option to CollectionSelect, options_from_collection_for_select, options_for_select
View include_selected_option.rb
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 Oct 23, 2015
Backup a directory, copy latest backup to S3
View backup-www.sh
#!/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 Oct 23, 2015
Backup all MySQL databases, copy latest backup to S3
View backup-db.sh
#!/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 Sep 28, 2015
requestAnimationFrame polyfill
View requestAnimationFrame.js
// 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() {
View CountUpTimer.java
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 Apr 13, 2014
android.util.Log without the tag
View OneLog.java
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);
}
View AsyncServerExampleService.java
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;