Skip to content

Instantly share code, notes, and snippets.

View pgaertig's full-sized avatar

Piotr Gaertig pgaertig

View GitHub Profile
@pgaertig
pgaertig / example.rb
Created April 12, 2012 10:27
JsonCommand
def destroy
#...
flash[:success] = t("entity_name.delete.success", :name => entity.name)
respond_to do |format|
format.html do
redirect_to :action=>:index
end
format.json { render :json => {
'delete-row'=>dom_id(entity)),
'flash-success' => flash.discard[:success]} }
@pgaertig
pgaertig / transpose_table.js
Created April 13, 2012 13:48
Transpose HTML table using jQuery
$(function() {
var t = $('#thetable tbody').eq(0);
var r = t.find('tr');
var cols= r.length;
var rows= r.eq(0).find('td').length;
var cell, next, tem, i = 0;
var tb= $('<tbody></tbody>');
while(i<rows){
cell= 0;
@pgaertig
pgaertig / development.rb
Created December 2, 2012 22:36
Dogslow like functionality for Rack and Rails
#Add this to your development.rb
config.middleware.use DogslowRack
@pgaertig
pgaertig / base64shim.js
Created September 14, 2013 22:12
Base64 (btoa/atob) shim adapted for WebKit's Web Workers, which miss these functions. See https://bugs.webkit.org/show_bug.cgi?id=55663
// Source: http://code.google.com/p/gflot/source/browse/trunk/flot/base64.js?r=153
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
@pgaertig
pgaertig / FactoryGrill.groovy
Last active June 15, 2019 04:09
FactoryGrill - db population made easy - a-la FactoryGirl
import groovy.sql.Sql
import org.codehaus.groovy.control.CompilerConfiguration
import java.sql.Connection
class FactoryGrill extends Script {
private Connection connection;
private Sql sql;
@pgaertig
pgaertig / TopLogger.js
Last active August 29, 2015 14:01
Records log messages and sends report to server in case of any error or warning.
function TopLogger(url, sessionId) {
var self = this;
var sid = sessionId;
var counter = 0;
var entries = [];
function consoleLog(type, msg) {
if(consoleChain && consoleChain[type]) {
try {
@pgaertig
pgaertig / rand-url-str.clj
Last active August 29, 2015 14:10
Random URL safe string generation in Clojure
(defn rand-url-str [len]
(let [chars (concat (range 48 58) (range 97 123))]
(apply str (repeatedly len #(char (rand-nth chars))))))
(rand-url-str 12)
; => "ypua82wote07"
@pgaertig
pgaertig / gist:d4cde29c688b8ec6db05
Created December 21, 2014 23:59
Setup PostgreSQL 9.4 with custom locales on Debian

Add locale, e.g. pl_PL.UTF-8, you don't have to set it as system default:

dpkg-reconfigure locales

Install PostgreSQL

apt-get update
apt-get install posgresql-9.4

Installation adds a cluster with default locale, recreate it with the correct one. The operation will destroy existing data in the cluster.

@pgaertig
pgaertig / time-example.cljs
Created April 2, 2015 21:09
Time format conversion in ClojureScript with MomentJS
(enable-console-print!)
(defn moment [arg] (.moment js/window arg))
(defn json-date-short [str]
(if str
(-> (moment str)
(.format "MM-DD HH:mm"))
"-")
)
@pgaertig
pgaertig / utils.cljs
Created May 4, 2015 21:19
MomentJS with ClojureScript
(ns kpapi.utils)
(enable-console-print!)
(defn moment [arg] (.moment js/window arg))
(defn fmt-date-short [str]
(if str (-> (moment str) (.format "MM-DD HH:mm")) "-"))
(defn fmt-date-time [str]