Skip to content

Instantly share code, notes, and snippets.

@josetapadas
josetapadas / gist:0cecfe0dfe57d1e3feb5
Created July 2, 2014 09:51
Convert JSON file to CSV
require 'csv'
require 'json'
def parse file
return unless file
csv_array = []
json_hash = JSON.parse(File.read( file, encoding: 'iso-8859-1' ))
json_hash.each do |mail, params|
csv_element = []
@josetapadas
josetapadas / gist:e5ce791bb5c87d7039f7
Created July 2, 2014 09:53
Simple Google Maps API JavaScript implementation
var google_map = {}
window.googleMapInitialize = function() {
var $map_address = $('#map-address');
var map_options = {
zoom: 17,
};
google_map = {
@josetapadas
josetapadas / gist:772d6ada7c10ea87cefd
Created July 2, 2014 09:55
Filesystem sync tool via ssh
import sys
import os
import time
import logging
import getopt
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
from watchdog.events import FileSystemEventHandler
class CamelCaravan(FileSystemEventHandler):
@josetapadas
josetapadas / gist:7e05261d8a3826b54ac8
Created July 17, 2014 10:18
Responsive media queries mixins
/* mixin for the big image gallery */
@mixin big-image-breakpoint($screen_size) {
@if $screen_size == small_device {
@media (max-width: 620px) {
@content;
}
}
@else if $screen_size == tablet {
@media (min-width: 620px) and (max-width: 991px) {
@josetapadas
josetapadas / gist:f9eec8ca7d9f214f0918
Created July 25, 2014 14:57
Dynamic single shot media query
var mediaQueryListElement = window.matchMedia("all and (min-width: 666px)");
function call_me(name) {
console.log("És um " + name);
mediaQueryListElement.removeListener(call_me.caller);
}
mediaQueryListElement.addListener(function() {
call_me("sugar");
});
@josetapadas
josetapadas / gist:cb8047c2044166ef8363
Created July 25, 2014 17:00
Load a script asynchronously for a responsive site (e.g, jQuery mobile)
var mediaQueryListElement = window.matchMedia("all and (max-width: 990px)");
function loadjQueryMobile() {
// listner to this callback very carefully, we should load this script only once
mediaQueryListElement.removeListener(loadjQueryMobile);
var helper_script = $('#holder-element').data('helper');
if (helper_script) {
$.getScript(helper_script)
@josetapadas
josetapadas / gist:3b70c20405a50bf5df1c
Created July 30, 2014 10:06
Insert or update on PostgresSQL
begin;
savepoint insert_save_point;
insert into params values('email', 'lol@lol.pt');
rollback to insert_save_point;
update params set value = 'lol@lol.pt' where name = 'email';
commit;
@josetapadas
josetapadas / gist:780d6104904d3df7e4ad
Created September 10, 2014 16:40
Simple responsive tooltip system
#seller-name {
color: #34495e;
&:hover {
cursor: help;
text-decoration: none;
}
/* pseudo element to put after our link */
&:after {
@josetapadas
josetapadas / .json
Created September 3, 2015 18:26
Sample reply from CruiseLine.com
{
"{": {
"\"request\":": {},
"{": {
"\"type\":\"ship\",": {},
"\"slug\":\"norwegian-breakaway\",": {},
"\"api\":\"api\",": {},
"\"key\":\"abc123\"": {},
"\"object\":": {},
"{": {
module CruisesCore
module Models
module Article
module Elasticsearch
extend ActiveSupport::Concern
included do
include ::Elasticsearch::Model
index_name "cruises-#{Rails.env}"