Skip to content

Instantly share code, notes, and snippets.

View kopos's full-sized avatar
🎯
Focusing

Poorna Shashank kopos

🎯
Focusing
View GitHub Profile
expr = "28+30+++39+32"
filter(bool, expr.split("+"))
filter(None, expr.split("+"))
bool(None) == bool('') == bool() == False
@kopos
kopos / out_of_turn_decorator.py
Created August 15, 2012 18:20
Decorator to handle out of turn requests from workers
import os
import sys
def get_curr_worker():
return 1
def is_worker_turn(f):
def _is_worker_turn(*args, **kwargs):
if args[0] == get_curr_worker():
return f(*args, **kwargs)
@kopos
kopos / inplace_replace.cc
Created August 15, 2012 18:24
Inplace String replacement - Kata
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define DELIM ' '
bool is_match(char * str, char * substr)
{
while (*substr++ == *str++);
@kopos
kopos / chaining.cpp
Created September 21, 2012 05:14
chaining in C++
#include <iostream>
#include <cstdlib>
class A {
private:
int a;
char b;
float c;
public:
@kopos
kopos / math.js
Created September 21, 2012 12:57
Javascript OOPS
function Vector2D(x, y) {
this.x = x;
this.y = y;
}
Vector2D.prototype.toString = function () {
return this.x +"i" + " + " + this.y + "j";
}
Vector2D.prototype.add = function (v) {
@kopos
kopos / rounded.html
Created September 23, 2012 15:36
Rounded icons
<html>
<head>
<style>
div {
background: url("me.png");
width:60px;
height:60px;
border-radius:100px;
border:4px solid #204A87;
}
@kopos
kopos / swap.c
Created September 25, 2012 00:25
Swap
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a = 5, b = 9;
a = a + b;
b = a - b;
a = a - b;
printf("%d %d\n", a, b);
@kopos
kopos / dynamic_rpc.py
Created November 22, 2012 15:40
RPC style python
import os
import sys
class A():
def say(self):
return "hello world"
@classmethod
def shout(cls):
return "hello class world"
@kopos
kopos / ring_code.erl
Last active December 10, 2015 19:28 — forked from anonymous/ring_code.erl
-module(ring).
-export([benchmark/2]).
%% run benchmark for N processes and M messages.
benchmark(N, M) ->
Pids = makering(N),
for(1, M, fun() -> spawn(fun() -> start(message, Pids) end) end).
%% setting up the process ring for sending
%% messages & return the Pids array
class A():
def say(self):
return "hello world"
@classmethod
def shout(cls):
return "hello class world"
@staticmethod
def scream():