Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys
import time
import psutil
import subprocess
wan_interface = subprocess.check_output([
'/bin/bash',
'-c',
'ifconfig | grep $(host $(hostname) | cut -d \ -f 4) -B1 | '
import socket
import struct
def ip2long(ip):
packedIP = socket.inet_aton(ip)
return struct.unpack("!I", packedIP)[0]
# Handshake
message = struct.pack('!qii', 0x41727101980, 0, 1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP

Keybase proof

I hereby claim:

  • I am refik on github.
  • I am refik (https://keybase.io/refik) on keybase.
  • I have a public key whose fingerprint is 990A 68C0 D7EF 3B22 B940 23B5 CD04 7237 F1C3 0B1B

To claim this, I am signing this object:

class ConnectingCars:
def minimizeCost(self, positions, lengths):
carts = sorted((positions[i], positions[i] + lengths[i]) for i in xrange(len(positions)))
move = lambda i: 0 if i == 0 else (carts[i][0] - carts[i-1][1]) * min(i, len(carts) - i)
return sum(move(i) for i in xrange(len(positions)))
@refik
refik / gist:ac60c379cb119225e544
Created January 14, 2015 08:29
topcoder final
class ConnectingCars:
def minimizeCost(self, positions, lengths):
carts = sorted((positions[i], positions[i] + lengths[i]) for i in xrange(len(positions)))
return sum((carts[i][0] - carts[i-1][1]) * min(i, len(carts) - i) for i in xrange(1,len(carts)))
@refik
refik / admin.menu.html
Created June 13, 2011 17:30
feincms TreeEditor admin item
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" xml:lang="en-us" >
<head>
<title>Select menu to change | Django site admin</title>
<meta name="robots" content="NONE,NOARCHIVE" />
<!-- STYLESHEETS -->
@refik
refik / settings.py
Created July 20, 2011 13:30
django project settings
# Django settings for audio project.
import os
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
@refik
refik / log
Created September 27, 2012 15:12
Make error log
make
Making all in doc
make[1]: Entering directory `/home/refik/code/X/~/sources/xorg/git/xorg/xserver/doc'
Making all in dtrace
make[2]: Entering directory `/home/refik/code/X/~/sources/xorg/git/xorg/xserver/doc/dtrace'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/refik/code/X/~/sources/xorg/git/xorg/xserver/doc/dtrace'
make[2]: Entering directory `/home/refik/code/X/~/sources/xorg/git/xorg/xserver/doc'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/refik/code/X/~/sources/xorg/git/xorg/xserver/doc'
@refik
refik / Makefile
Created September 27, 2012 15:12
Makefile
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@refik
refik / jhbuildrc
Created September 27, 2012 15:17
jhbuildrc
#!python
#######################################################################################
# This is a checkout and build configuration for building Xorg
#
# This can be copied to ~/.jhbuildrc and then run 'jhbuild build xserver'
#
#######################################################################################
moduleset = 'http://cgit.freedesktop.org/xorg/util/modular/plain/xorg.modules'
checkoutroot = '~/sources/xorg/git'