Skip to content

Instantly share code, notes, and snippets.

View hisapy's full-sized avatar
🏠
Working from home

Hisa hisapy

🏠
Working from home
View GitHub Profile
@hisapy
hisapy / JobSearchGoogleSheet.js
Last active December 11, 2019 21:06
JavaScript for Google Sheet to track job Search
/**
* Google Sheet:
* https://docs.google.com/spreadsheets/d/1rkPwzZIE60Tjdk-Rq18tewy48vdpWk1dSD3wr4wp81w/copy
*
* For more info see:
* https://medium.com/@hisa_py/google-sheet-to-track-job-search-68c88c699d33
*/
// globals
var STATUS_COLUMN = 12;
@hisapy
hisapy / imperative_vs_functional.js
Last active October 24, 2018 21:07
"Imperative" vs Functional Javascript example
/*
Given props routeIndices such as [0, 2, 2, 4] and routes such as [RouteObj, RouteObj] passed to a React component,
use the routeIndices to traverse down the routes tree, via RouteObj children, to get the RouteObj title attribute.
For example, a <Route title="Home" /> from Found.
*/
getTitleFromRouteImperative() {
const { routeIndices, routes } = this.props;
@hisapy
hisapy / view_helpers.rb
Created July 25, 2015 17:08
Scoping in rspec view specs
##
# Inspired in:
# https://github.com/robinroestenburg/tamingthemindmonkey-sinatra/blob/master/posts/2011-11-07-capybara-matchers-and-scoping-in-view-specs.markdown
# and
# https://github.com/jnicklas/capybara/blob/d087965f8110f4098a11f52bb18edea88df277ac/lib/capybara/session.rb#L281
# I created my own nestable version of within() scope matcher
#
# Just put this in spec/support/view_helpers.rb
#
# Examples
@hisapy
hisapy / gist:3df6d80c9a661d018ee4
Last active August 29, 2015 14:25
Arel inside select list
class Client
has_many :sales, dependent: :restrict_with_error
# This is an example of how to use an Arel projection inside a select list.
scope :with_sales_totals, -> {
clients = arel_table
sales = Sale.arel_table
# this is will be agregated in the final query in the select list
receivables_sum = sales
@hisapy
hisapy / hash_to_xml_example.rb
Created May 8, 2015 16:32
Create XML from Hash recursively using Nokogiri
hash_tree = {} # hash where all the members are also hashes, even the "leaf nodes"
def xml_node(node, children, xml)
xml.send(node){
children.each do | n, c |
xml_node(n, c, xml)
end
}
end
builder = Nokogiri::XML::Builder.new do | xml |
@hisapy
hisapy / spec_helper.rb
Last active August 29, 2015 14:11
RSpec: call VCR registered request matcher from inside custom matcher
# This is an excerpt from a spec_helper file with a section to configure VCR
#
# In lines 30 and 32 you can see examples of how to call a VCR registered request matcher from inside another.
# This is useful when running an example that makes a request to multiple external resources or APIs.
# Without this the requests were recorded the 1st time but subsequent requests raised VCR::Errors::UnhandledHTTPRequestError
VCR.configure do |c|
c.ignore_localhost = true
c.cassette_library_dir = 'spec/cassettes'
c.hook_into :webmock
@hisapy
hisapy / verify_rspec_failed_examples.rb
Last active August 29, 2015 14:07
Count false/real positives based on rspec failed examples
#!/usr/bin/env ruby
require 'getoptlong'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--rspec-command', '-r', GetoptLong::REQUIRED_ARGUMENT ],
[ '--suite-output-file', '-f', GetoptLong::REQUIRED_ARGUMENT ]
)
@hisapy
hisapy / persistence-promises-example.js
Last active August 29, 2015 14:04
Wrapping persistencejs methods to use jQuery Promises
//This depends on jquery and persistencejs.
/**
* Given a"model" Product. Instances of Product persist their data to Web SQL (persistencejs)
*/
var Product = persistence.define('products', {
name: 'TEXT',
image_path: 'TEXT',
created_at: 'DATE',
updated_at: 'DATE'
$.ajax({
crossDomain: true,
type: "GET",
url: "https://ws.elfarosrl.net:3000/categories",
contentType: "application/json; charset=utf-8",
data:{
access_token: "a7632c8200bc27b95ed11c999ff20c944dfbb0a8",
last_imported_at: -1
}
}).done(function(data, textStatus, jqXHR){
@hisapy
hisapy / gist:5390206
Created April 15, 2013 18:26
Rails ActiveRecord .select() not working with .joins() and .count()
# Given the following
ExitPoll.select('listas.id, numero, listas.nombre, listas.color')
.joins(:chapa_presidencial)
.count(group: :chapa_presidencial)
# Rails executes the following 2 SQL queries
SELECT COUNT(*) AS count_all, chapa_presidencial_id AS chapa_presidencial_id
FROM `exit_polls` INNER JOIN `listas` ON `listas`.`id` = `exit_polls`.`chapa_presidencial_id`
GROUP BY chapa_presidencial_id