Skip to content

Instantly share code, notes, and snippets.

class TreeNode:
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
class BinarySearchTree:
def __init__(self):
class ListNode:
def __init__(self, value, next):
self.value = value
self.next = next
class LinkedList:
def __init__(self):
self.head = None
public static boolean isElementPresentSorted(int[] m, int elem) {
// BINARY SEARCH
int first = 0, last = m.length - 1;
while (first <= last) {
int middle = first + (last - first) / 2;
if (m[middle] == elem) {
return true;
} else if (m[middle] < elem) {
first = middle + 1;
} else {
@alejolp
alejolp / testadler32combine.c
Created January 27, 2017 07:16
Test program for ADLER32 Combine function
/*
* Calculate the ADLER32 of a sequence of bytes by chunks, allowing to
* use threads to speed up the calculations.
*
* By Alejandro Santos <alejandro.santos@cern.ch>
*/
#include <stdio.h>
@alejolp
alejolp / dump_root_histogram.cpp
Last active November 15, 2016 15:43
List all the files inside a ROOT file and dump an Histogram or object
/*
* List the files inside a ROOT file and print the specific histogram or object.
*
* By Alejandro Santos
*
* Build with: g++ dump_root_hist.cpp -Wall -g $(root-config --cflags --glibs)
*
*/
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
// boost intrusive pointer example
// change boost::thread_unsafe_counter to boost::thread_safe_counter for a thread safe version
// you shouldn't be passing smart pointer among threads anyway...
class Object : private boost::noncopyable, public boost::intrusive_ref_counter<Object, boost::thread_unsafe_counter> {
protected:
@alejolp
alejolp / dmesg.txt
Last active June 1, 2016 14:14
TAP AX.25
[ 2525.145364] IPv6: ADDRCONF(NETDEV_CHANGE): em1: link becomes ready
[ 2589.973799] skbuff: skb_under_panic: text:ffffffffa0a36810 len:20 put:15 head:ffff880223282a00 data:ffff8802232829fe tail:0x12 end:0xc0 dev:<NULL>
[ 2589.973854] ------------[ cut here ]------------
[ 2589.976829] kernel BUG at /build/linux-RYwSFv/linux-3.16.7-ckt20/net/core/skbuff.c:100!
[ 2589.980700] invalid opcode: 0000 [#3] SMP
[ 2589.984244] Modules linked in: ax25 tun ctr ccm bnep rtsx_usb_ms memstick rtsx_usb_sdmmc rtsx_usb openafs(PO) nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc snd_hda_codec_hdmi snd_hda_codec_conexant snd_hda_codec_generic uvcvideo videobuf2_vmalloc videobuf2_memops videobuf2_core v4l2_common videodev media ecb arc4 brcmsmac cordic brcmutil btusb bluetooth b43 6lowpan_iphc mac80211 cfg80211 ssb x86_pkg_temp_thermal intel_powerclamp mmc_core rng_core intel_rapl pcmcia coretemp pcmcia_core iTCO_wdt iTCO_vendor_support kvm_intel kvm crc32_pclmul joydev cryptd psmouse evdev i2c_i801 serio_raw pc
#!/usr/bin/env python3
# coding: utf-8
import os
import pprint
import sys
def tokenize_file(file_name):
output = []
with open(file_name, 'r', encoding="utf-8") as f:
#!/usr/bin/env python
"""
http://en.wikipedia.org/wiki/Bin_packing_problem
"""
import os, sys, random
def empaquetar_ordenado(E, L, Ordenar=True):
if Ordenar:
import java.util.Date;
import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPAdministrator;
import com.espertech.esper.client.EPRuntime;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.UpdateListener;
import com.espertech.esper.client.time.CurrentTimeEvent;