Skip to content

Instantly share code, notes, and snippets.

View 4e1e0603's full-sized avatar
🎯
I may be slow to respond.

David Landa 4e1e0603

🎯
I may be slow to respond.
  • Prague, Czech Republic
View GitHub Profile
@why-not
why-not / gist:4582705
Last active November 6, 2024 04:35
Pandas recipe. I find pandas indexing counter intuitive, perhaps my intuitions were shaped by many years in the imperative world. I am collecting some recipes to do things quickly in pandas & to jog my memory.
"""making a dataframe"""
df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
"""quick way to create an interesting data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
"""convert a dictionary into a DataFrame"""
"""make the keys into columns"""
df = pd.DataFrame(dic, index=[0])
@harvimt
harvimt / alchemical_model.py
Created February 2, 2013 20:41
SQLAlchemy to/from PyQt Adapters
#!/usr/bin/env python2
#-*- coding=utf-8 -*-
# © 2013 Mark Harviston, BSD License
from __future__ import absolute_import, unicode_literals, print_function
"""
Qt data models that bind to SQLAlchemy queries
"""
from PyQt4 import QtGui
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt
import logging # noqa
@philsquared
philsquared / C++ Extension Methods
Created April 11, 2013 23:45
How to write the "left arrow operator" to enable extension methods in C++
#include <cassert>
#include <iostream>
template<typename T, typename R=void>
struct ExtMethod {
ExtMethod& operator - () {
return *this;
}
template<typename U>
html{
background-image: linear-gradient(#0ff 1px, transparent 1px);
background-size: auto 1.5em;
}
@jaguilar
jaguilar / gist:5533466
Created May 7, 2013 15:22
Clang format on save in sublime text 3
import sublime, sublime_plugin
import subprocess
class ClangFormatCommand(sublime_plugin.TextCommand):
def run(self, edit):
r = sublime.Region(0, self.view.size())
try:
p = subprocess.Popen(
['clang-format', '--style', 'Google'],
stdin=subprocess.PIPE,
@ShepBook
ShepBook / gist:5713899
Last active August 22, 2020 06:35
Installing Clojure and Clojure Koans with Leiningen on Linux Mint 15

Installing Clojure and Clojure Koans with Leiningen on Linux Mint 15

Remove Existing OpenJDK

Generally, I'd recommend running Oracle's Java, if you're doing Clojure development. Seeing how Clojure is built around the standard JVM from Oracle, it seems like it would be best to use that. First, let's remove the existing OpenJDK from our OS.

Search for OpenJDK

$ dpkg --get-selections | grep jdk
@Mr-Byte
Mr-Byte / linq.rs
Last active August 13, 2017 18:00
Proof of concept macro to implement LINQ syntax in rust.
macro_rules! query(
(from $v:ident in $c:ident $(where $mw:expr)* select $ms:expr) =>
($c.filter_mapped(|&$v| if(true $(&& $mw)*) { Some($ms) } else { None }))
)
fn main()
{
let nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let result1 = query!(from x in nums select x * 2);
@mavnn
mavnn / part1.fs
Created October 14, 2013 09:55
Introducing F# Syntax
// Let's send an email!
@Fristi
Fristi / Aggregate.hs
Last active December 21, 2024 10:17
DDD/Event Sourcing in Haskell. Implemented an aggregate as a type class and type families to couple event, command and error types specific to the aggregate. Errors are returned by using Either (Error e) (Event e). Applying Applicative Functors fits here well to sequentially check if the command suffice.
{-# LANGUAGE TypeFamilies #-}
import Data.Function (on)
import Control.Applicative
data EventData e = EventData {
eventId :: Int,
body :: Event e
}
@ToJans
ToJans / InventoryItems.hs
Last active December 21, 2024 10:20
Haskell implementation of Greg Young's CQRS sample: https://github.com/gregoryyoung/m-r Love the sheer elegance of Haskell; no need for all that infrastructure crap
module InventoryItems(Command(..), Event(..), handle) where
import Data.Maybe(isJust)
type Id = String
type Name = String
type Amount = Int
data Command = CreateInventoryItem Id
| RenameInventoryItem Id Name