Skip to content

Instantly share code, notes, and snippets.

@mankind
mankind / attachments.hbs
Created November 18, 2014 09:53
Emberjs file upload with HTML-5 formData
{{upload-file action="saveUpload"}}
@mankind
mankind / cms.js
Last active August 29, 2015 14:14
emberjs course
ember new cms
ember generate model page navbar:string title:string body:string
import DS from 'ember-data';
export default DS.Model.extend({
navbar: DS.attr('string'),
title: DS.attr('string'),
body: DS.attr('string'),
//https://github.com/maccman/abba/blob/master/app/assets/javascripts/client/index.coffee
var extend, getCookie, host, request, setCookie,
slice = [].slice;
host = function(url) {
var parent, parser;
parent = document.createElement('div');
parent.innerHTML = "<a href=\"" + url + "\">x</a>";
parser = parent.firstChild;
return "" + parser.host;
@mankind
mankind / gTest.R
Created July 27, 2015 08:49
GTEST CALCULATION WITH R
#https://rforge.net/doc/packages/Deducer/likelihood.test.html
#http://www.pmc.ucsc.edu/~mclapham/Rtips/G%20test.txt
# Log-likelihood tests of independence & goodness of fit
# Does Williams' and Yates' correction
# does Monte Carlo simulation of p-values, via gtestsim.c
#
# G & q calculation from Sokal & Rohlf (1995) Biometry 3rd ed.
# TOI Yates' correction taken from Mike Camann's 2x2 G-test fn.
# GOF Yates' correction as described in Zar (2000)
@mankind
mankind / gTest2.R
Last active August 29, 2015 14:25
another function to calculate gtest in R
#http://www.stat.wisc.edu/~st571-1/gtest.R
#see page 2 for data & page 17 for g-test http://www.stat.wisc.edu/~st571-1/06-tables-2.pdf
# Bret Larget
# October 28, 2010
# September 30, 2011
# Use source() to read this file into R to use it.
# Example:
@mankind
mankind / rails-elasticbean.txt
Created March 31, 2016 12:39
Deploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic Beanstalk by Julien SIMON, Principal Technical Evangelist @ Amazon Web Services
18/02/2016
http://www.slideshare.net/JulienSIMON5/deploying-a-simple-rails-application-with-aws-elastic-beanstalk
1. . Create a Git repository with AWS CodeCommit
$ aws codecommit create-repository --repository-name blog --region us-east-1 --repository-description "ElasticBeanstalk demo"
$ git clone ssh://git-codecommit.us- east-1.amazonaws.com/v1/repos/blog
2. Create a new Rails application
@mankind
mankind / rails-aws-ses-ruby-aws-sdk-2.rb
Created March 31, 2016 12:47
Getting started aws ses and demo using aws_sdk gem version 2
Getting started aws ses
http://codechannels.com/video/amazonwebservices/cloud/getting-started-with-amazon-ses/
1. Verify email address
In the sandbox you can send email only from emails yiu have verified.
Go to email AWS SES then on the left clcik on 'verified senders'
to start the verification process:
a. click 'verify a ne sender'
in the dialogue box add your email and click submit. you will receive
@mankind
mankind / base.html
Last active July 21, 2016 09:45
Simple user defined form fields using html and javacsript. see demo: http://codepen.io/anon/pen/dMEywE and http://jsbin.com/vikibacese/edit?html,js,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title> User define form element Example </title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.1.css">
<style>
#div1 {

Assuming this table definition:

CREATE TABLE segments (segments_id serial PRIMARY KEY, payload jsonb);
With JSON values like this:

INSERT INTO segments (payload)
VALUES ('{
     "a": [
        {

"kind": "person",

@mankind
mankind / rails-jsonb-queries
Last active May 23, 2024 06:47
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")