Skip to content

Instantly share code, notes, and snippets.

View dyno's full-sized avatar
🏠
Working from home

Dyno Fu dyno

🏠
Working from home
View GitHub Profile
@retronym
retronym / mvn2sbt.scala
Created May 3, 2010 17:17
mvn2sbt: quick hack to turn <dependencies> into SBT
object scala {
val version = "SCALA_VERSION$"
}
val xml = <dependencies>
<dependency>
<groupId>org.scalanlp</groupId>
<artifactId>scalala_${scala.version}</artifactId>
<version>0.3.1</version>
</dependency>
@ssokolow
ssokolow / get_default_gateway_linux.py
Created July 2, 2011 12:15
Snippet for getting the default gateway on Linux
#Snippet for getting the default gateway on Linux
#No dependencies beyond Python stdlib
import socket, struct
def get_default_gateway_linux():
"""Read the default gateway directly from /proc."""
with open("/proc/net/route") as fh:
for line in fh:
fields = line.strip().split()
@siddhi
siddhi / pyconindia_dsl.py
Created September 16, 2011 06:33
Domain Specific Languages in Python - Pycon India - 17 Sep 2011
from pyparsing import *
# By default, PyParsing treats \n as whitespace and ignores it
# In our grammer, \n is significant, so tell PyParsing not to ignore it
ParserElement.setDefaultWhitespaceChars(" \t")
def parse(input_string):
def convert_prop_to_dict(tokens):
"""Convert a list of field property tokens to a dict"""
prop_dict = {}
@scoffey
scoffey / webtail.py
Created January 15, 2012 20:04
HTTP server that provides a web interface to run "tail" on a file, like the Unix command
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
HTTP server that provides a web interface to run "tail" on a file,
like the Unix command.
This is a standalone script. No external dependencies required.
How to invoke:
@imankulov
imankulov / file_lock.py
Last active December 5, 2017 06:46
This is how we do file locks (python 2.5+)
from __future__ import with_statement
import os
import time
import fcntl
import contextlib
@contextlib.contextmanager
def file_lock(filename, lock_type, timeout=None):
fd = open(filename, 'w')
fctnl_lock_type = getattr(fcntl, lock_type, None)
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active June 5, 2024 22:16
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@MichaelWS
MichaelWS / dataSourcecsv.py
Created June 28, 2013 18:41
example datasource of zipline
"""
leverage work of briancappello and quantopian team
(especcially twiecki, eddie, and fawce)
"""
import pandas as pd
from zipline.gens.utils import hash_args
from zipline.sources.data_source import DataSource
import datetime
import csv
import numpy as np
@stantonk
stantonk / scalaforpy
Last active August 28, 2021 10:13
Scala for Python Programmers, examples
/*
Notes:
Despite Scala's appearances, it is, in fact, a Statically Typed language.
It has just eliminated a great deal of the "type vomit" people are used
to seeing in Statically Typed languages (e.g. C, C++, Java). It often
can infer the type on its own. It also combines functional and
object-oriented programming paradigms in a fashion that feels similar
to Python.
*/
@davideicardi
davideicardi / README.md
Last active March 8, 2023 15:05
Write and read Avro records from bytes array

Avro serialization

There are 4 possible serialization format when using avro:

@ianoc-stripe
ianoc-stripe / S3FileSystem.scala
Created September 25, 2018 23:00
S3FileSystem code to wrap s3
/*
Copyright 2018 Stripe Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OT