Skip to content

Instantly share code, notes, and snippets.

View ejamesc's full-sized avatar

Cedric Chin ejamesc

View GitHub Profile
Traceback (most recent call last):
File "/Users/cedric/Projects/FloatingCube/epos/odoo-temp/openerp/http.py", line 539, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Users/cedric/Projects/FloatingCube/epos/odoo-temp/openerp/http.py", line 576, in dispatch
result = self._call_function(**self.params)
File "/Users/cedric/Projects/FloatingCube/epos/odoo-temp/openerp/http.py", line 312, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/Users/cedric/Projects/FloatingCube/epos/odoo-temp/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/Users/cedric/Projects/FloatingCube/epos/odoo-temp/openerp/http.py", line 309, in checked_call
var _super = module.Order;
module.Order = module.Order.extend({
init_from_JSON: function(json) {
_super.prototype.init_from_JSON.apply(this,arguments);
this.note = json.note;
},
export_as_JSON: function(){
var json = _super.prototype.export_as_JSON.apply(this,arguments);
@ejamesc
ejamesc / mithrildemo.js
Last active November 29, 2015 09:25
moi first mithril app
var ModalWidget = {
view: function(ctrl, opts) {
return m(".modal", [
m(".modal-dialog", [
m(".modal-header", [
m("h2", opts.title)]),
m(".modal-body", [m("input[type=text]", {placeholder: "http://", oninput: m.withAttr("value", opts.pastedUrl), value: opts.pastedUrl()}),
!opts.validUrl() ? m(".valid-message", [m("em", "Hey, that's not a valid URL!")]) : null,
].concat(opts.body)),
m("a.close[href=javascript:;]", {onclick: function(e) {
def find_valleys(arr):
peaks = []
for i in xrange(0, len(arr)):
if i == 0 and arr[i] > arr[i + 1]:
peaks.append((i, arr[i]))
elif i == (len(arr) - 1) and arr[i] > arr[i - 1]:
peaks.append((i, arr[i]))
elif arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
peaks.append((i, arr[i]))
# Find two numbers in a sorted arr that sum to s
def sum(arr, s):
print arr
p1, p2 = 0, len(arr) - 1
while p1 < p2:
# print p1, p2
curr = arr[p1] + arr[p2]
if curr == s:
return arr[p1], arr[p2]
@ejamesc
ejamesc / rainfall.py
Last active October 6, 2015 16:41
FINALLY.
from sys import stdin, maxint
class WaterCell:
def __init__(self, id_tuple, value):
self.isPartitioned = False
self.id = id_tuple
self.value = value
self.next = None
self.group = -1
def maxdiff(numbers):
if len(numbers) < 2 or len(numbers) == 0:
return 0
curr_max = numbers[0]
max_diff = 0
for x in numbers:
curr_max = max(x, curr_max)
max_diff = max(curr_max - x, max_diff)
def maxdiff(numbers):
if len(numbers) < 2 or len(numbers) == 0:
return 0
max, min, max_diff = maxdiff_core(numbers, 0, len(numbers) - 1)
return max_diff
def maxdiff_core(numbers, start, end):
if end == start:
return numbers[start], numbers[start], 0
log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit
@ejamesc
ejamesc / gist:19c19d8ff5236dc8486f
Last active August 29, 2015 14:23
Detect Browser Type JS
navigator.sayswho = (function(){
var ua = navigator.userAgent, tem,
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+ (tem[1] || '');
}
if (M[1] === 'Chrome') {
tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera');