Skip to content

Instantly share code, notes, and snippets.

View hachpai's full-sized avatar
👾
chasing ghosts

hachpai hachpai

👾
chasing ghosts
View GitHub Profile
@hachpai
hachpai / ajax_search.php
Last active June 1, 2017 07:24
making generic search usable with API calls
//html/ajax_search.php
<?php
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
require '/includes/generic_search.inc.php'; //requiring html/includes/generic_search.inc.php
set_debug($_REQUEST['debug']);
//check auth based on session
if (!$_SESSION['authenticated']) {
echo "Unauthenticated\n";
@hachpai
hachpai / handshake.ino
Last active August 29, 2015 14:12
RF24: establishing a connection protocol.
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#include <SPI.h>
#include "nRF24L01.h"
@hachpai
hachpai / product_filters.rb
Last active December 14, 2015 19:39 — forked from Ranger-X/product_filters.rb
In order to make search on range of numerical option values, I've implemented this version. As spree stocks option value in a string, I've to cast it to compare. In the original version of this gist, I was unable to make or join between the created scope. With arel table, no problem.
def ProductFilters.ov_range_test(range1, range2)
ov = Arel::Table.new("spree_option_values")
cast = Arel::Nodes::NamedFunction.new "CAST", [ ov[:presentation].as("integer")]
comparaisons = cast.in(range1..range2)
comparaisons
end
Spree::Product.add_search_scope :screenSize_range_any do |*opts|
conds = opts.map {|o| Spree::ProductFilters.screenSize_filter[:conds][o]}.reject {|c| c.nil?}
scope = conds.shift