Skip to content

Instantly share code, notes, and snippets.

@trestles
trestles / nokogiri
Last active December 27, 2021 17:54
=begin
doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML
<style>.emphasized { font-weight: bold } </style>
<h1>Three's Company</h1>
<div class='something'><strong>A love triangle.</strong></div>
<h1>other things</h1>
<style>.more-bold { font-weight: bold }</style>
EOHTML
require('dotenv').config();
const puppeteer = require('puppeteer-extra')
const select = require ('puppeteer-select');
/*
before (async function () {
global.baseURL = '';
console.log("within before");
});
*/

1. Voting

I created a users, referendums, questions, and answers tables in the code below. Based upon requirements, it sounds like you will be able to identify users - I'll assume that they are logged in via an auth mechanism. Also, I would suspect that you wouln't want a user to answer twice so I added an aswered_questions to user in light of not wanting to leak user information into answers. One could probably use a hashed value to identify users at - I'd probably need more info.

Re anomynity of answers, at small scale this could potentially be traced but I'm assuming that there are enough answers that, probabilistically, this wouldn't be achievable.

In the answers table, I changed the answer_value to a Bool. I suspect that there will be more than just true / false in the future but for time being, this is sufficient. There would probably need to be an answer_choices table or possibly convert the answer_value to an enum. However, an enum would not be 4th Normal Form (that's arguable though).

I'

def my_flatten(arr)
result = []
return result unless arr.is_a?(Array)
arr.each do |value|
if value.is_a?(Array)
my_flatten(value).each { |y| result << y}
else
result << value if value.is_a?(String)
end
end
func renderTopMenuItemView(){
var miTopViewRunningY: CGFloat = 10.0
let miTopView=UIView()
miTopView.frame = CGRectMake(0, 64, self.screenWidth, 100)
miTopView.backgroundColor = UIColor.yellowColor()
miTopView.layer.borderColor=UIColor.blackColor().CGColor
miTopView.layer.borderWidth=2.0
$('body').on('click','.toggle_show_add_tn_form', function(){
var menu_item_id_val=$(this).attr('data-menu-item-id');
var this_form=$('#tn-' + menu_item_id_val);
var $that=$(this);
this_form.toggle("slow",function(){
if(this_form.is(":visible")){
$that.text('hide tasting note form')
}else{
$that.text('show tasting note form')
// assign to body tag such that if it's html written to DOM after page has been loaded, if not
// $('.buy-btn').on('click', function(){
$('body').on('click', '.buy-btn', function(){
if($("#package-1").is(':checked')){
// get pacakge-sub-values and build data_val
data_val={{package_1:true, ....}}
}else if($("#package-2").is(':checked')) {