Skip to content

Instantly share code, notes, and snippets.

View neotrinity's full-sized avatar

Gokulnath Haribabu neotrinity

View GitHub Profile
@neotrinity
neotrinity / .vimrc
Last active December 31, 2015 22:39
My vimrc for python
syntax on
set nocompatible
set clipboard=unnamed " yank and paste with the system clipboard
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
@neotrinity
neotrinity / gold_mines.cpp
Last active January 3, 2016 09:09
Gold Mines - Hacker Earth - I have defensively coded the constraints
#include <stdio.h>
#include <time.h>
using namespace std;
int main()
{
// declarations & initialisations
//time_t start = time(NULL);
//int sec;
import array
import sys
MIL = 10**6
def running_sum(a):
tot = 0
for item in a:
i = int(item)
if i < 0 or i > MIL:
@neotrinity
neotrinity / fancy_sort.py
Created May 12, 2014 22:58
Fancy sort - longest to smallest and then to longest
def fancy_sort(countries):
""" countries -> list of countries """
sorted_countries = [(-1 * len(x[1]) if x[0] % 2 else len(x[1]), x[1])
for x in enumerate(sorted(countries, key=len))]
return [x for x in sorted(sorted_countries, key=lambda x: x[0])]
countries = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua & Deps', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Central African Rep', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo', 'Congo {Democratic Rep}', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Fiji
import sys
## Typical Usage:
## python parse_transalations.py 'path/to/messages.po'
## This prints the strings and their respective translations
def clean(s):
""" Quick and dirty scrubbing of the data """
return s.replace('"', '').replace('msgid ', '').replace('msgstr ', '')
@neotrinity
neotrinity / hash_folds.hs
Last active August 29, 2015 14:04
Decryption problem in haskell and python
-- Using folds version
import Data.List
import Data.Maybe
letters = "acdegilmnoprstuw"
getIndexOf :: Char -> String -> Int
getIndexOf x xs = fromMaybe (-1) (elemIndex x xs)
hashacc :: Int -> Char -> Int
@neotrinity
neotrinity / elm_clock_tutorial.elm
Last active August 29, 2015 14:06
elm clock tutorial
main = lift clock (every second)
number n = let angle = degrees (90 - 6 * (n * 5))
in move (100 * cos angle, 100 * sin angle) (toForm (asText n))
displayNumbers = group (map number [1..12])
clock t = collage 400 400 [ outlined (solid blue) (circle 110)
import simplegui
import random
class Direction(object):
UP, DOWN, LEFT, RIGHT = range(4)
class GameState(object):
RUNNING, FINISHED = range(2)
import sys
# needed for casting PyCObject to void pointer
from ctypes import pythonapi, c_void_p, py_object
from PySide.QtCore import *
from PySide.QtGui import *
import gobject
import pygst
@neotrinity
neotrinity / abc_tester.py
Created November 5, 2014 12:57
getting my head around abc
import abc
class AbstractV(object):
__metaclass__ = abc.ABCMeta
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():