Skip to content

Instantly share code, notes, and snippets.

@broqdev
broqdev / reverse_cstr.c
Created September 21, 2012 05:16
CareerCup 1.2, reverse cstr, c/c++
#include "string.h"
void reverse_cstr(char* cstr);
void reverse_cstr_complex(char* cstr);
static void reverse_char(char* cstr, int len, int reverse_count);
static void reverse_inner(int* left, int* right);
static void reverse_int(char* cstr, int len, int reverse_count);
void test() {
@broqdev
broqdev / derivedmethod.py
Last active December 10, 2015 12:18
how to call derived method in parent class
class Foo(object):
def __init__(self):
self._func = None
def callDerivedFunc(self):
# self._func() # call bound method
# self._func(self) # call unbound method
method = self._func
method(self) # call unbound method
@broqdev
broqdev / querykarg.py
Created January 2, 2013 12:30
query function's definition
arg_count = foo.func_code.co_argcount
args = foo.func_code.co_varnames[:arg_count]
args_dict = {}
for k, v in d.iteritems():
if k in args:
args_dict[k] = v
foo(**args_dict)
--- install2.js 2013-01-25 15:32:38.358227000 +0800
+++ install.js 2013-01-25 14:29:55.639011700 +0800
@@ -108,7 +108,9 @@
unzipStream.on('error', finishIt)
unzipStream.on('close', finishIt)
- var readStream = fs.createReadStream(downloadedFile)
+ var zipPath = path.normalize('d:/node/phantomjs-1.8.0-windows.zip')
+ var readStream = fs.createReadStream(zipPath)
+ //var readStream = fs.createReadStream(downloadedFile)
@broqdev
broqdev / circlemax.py
Last active December 24, 2015 13:29
possible solution for circle array problem.
# -*- coding: utf-8 -*-
'''
A circular array A[1, . . . , n] is an array such that n ≥ 3 and A[1] and A[n] are considered to be adjacent elements just like A[1] and A[2], A[2] and A[3], etc., are adjacent.
We are given a circular array A[1, . . . , n] of non-negative integers. For any i, j ∈ {1, 2, . . . , n} such that i != j, dist(i, j) = max {|i − j|, n − |i − j|}.
Design a linear time algorithm that computes a maximum number t such that for some i, j ∈ {1, 2, . . . , n}, i != j, t = A[i] + A[j] + dist(i, j).
'''
def distant(i, j, n):
dis = abs(j-i)
@broqdev
broqdev / circlemax_linear.py
Last active December 24, 2015 17:39
Linear solution for circle array problem
def distant(i, j, n):
i%=n
j%=n
dis = abs(j-i)
if ((n-dis) > dis):
dis = n-dis
return dis
@broqdev
broqdev / coin.py
Created October 19, 2013 04:22
One solution to Coin Change problem, not the best.
# deno = [2, 5, 13]
# deno_nums = [1, 3, 1]
# target = 17
deno = [1, 2, 7, 11]
deno_nums = [5, 18, 1, 7]
target = 82
# every cell has 4 parts:
# one pointer to the previous cell which is part of current combination
当前是i,j in [0...i),first pass算max(A[i]+A[j]+i-j),second pass 算max(A[i]+A[j]+n-(i-j))
第一次用公式max_value = max(max_value+1, A[i-1]+1)
第二次用公式max_value = max(max_value-1, A[i-1]+n-1)
for i in xrange(len(ar)):
#try to update max_value
ret = max(ret, A[i]+max_value)
这个循环写两次,用两个不同的公式
@broqdev
broqdev / cx_oracle_instructions.md
Last active April 9, 2016 00:04 — forked from thom-nic/cx_oracle_instructions.md
Installing CX Oracle for Python & Mac OS X. Instructions exist around the web, but they seem to be piecemeal and incomplete.

Installing cx_Oracle (x86_64) for Mac OSX (tested on El Capitan 10.11.4)

Assume you've got homebrew installed.

Assume python is installed through

brew install python --universial

Install instant client

@broqdev
broqdev / Foo.scala
Last active March 3, 2019 09:16
spark deadlock
package com.test
import java.net.{URI, URL}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory
import org.apache.spark.sql.SparkSession
import org.apache.hadoop.fs.Path;
// build into a jar and run with spark-submit