Skip to content

Instantly share code, notes, and snippets.

@daixque
daixque / ArithmeticParser.scala
Created January 14, 2012 09:00
Arithmetic parser/evaluator written in scala using parser combinator
import scala.util.parsing.combinator._
abstract class Value {
def eval():Double
}
case class Number(n:Double) extends Value {
def eval():Double = n
}
case class Binomial(op: String, v1:Value, v2:Value) extends Value {
def eval():Double = op match {
@kbaribeau
kbaribeau / gist:4495181
Created January 9, 2013 17:46
The source code for the unix `ping` command, taken from here: http://ftp.arl.army.mil/~mike/ping.html
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# Makefile ping.1 ping.c ping.shar newping.1 newping.c
echo x - Makefile
cat > "Makefile" << '//E*O*F Makefile//'
@dajobe
dajobe / dir.scala
Last active May 22, 2018 14:33
Get the methods on a class / object - aka python dir()
// Inspired by http://stackoverflow.com/questions/2886446/how-to-get-methods-list-in-scala
def dir(x: AnyRef): Unit = println(x.getClass.getMethods.map(_.getName).distinct.sorted.mkString(" "))
scala> dir("")
charAt codePointAt codePointBefore codePointCount compareTo compareToIgnoreCase concat contains contentEquals copyValueOf endsWith equals equalsIgnoreCase format getBytes getChars getClass hashCode indexOf intern isEmpty lastIndexOf length matches notify notifyAll offsetByCodePoints regionMatches replace replaceAll replaceFirst split startsWith subSequence substring toCharArray toLowerCase toString toUpperCase trim valueOf wait
@aubricus
aubricus / License
Last active November 14, 2024 11:22
Python Progress Bar
Copyright 2020 Aubrey Taylor
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 OTH
@demmer
demmer / slack-messages-by-user.py
Created December 2, 2016 22:59
count slack messages posted to a channel by user
#!/usr/bin/python
'''
Script to count messages by user posted to a channel for a given date range.
Install:
# sudo pip install slackclient
Also you will need to obtain a slack API token:
https://api.slack.com/docs/oauth-test-tokens
@simonw
simonw / recover_source_code.md
Last active September 28, 2024 08:10
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@dodo5522
dodo5522 / flickr_uploader.py
Last active May 4, 2023 21:40
Python script to upload a photo into flickr.
#!/usr/bin/env python2
# -*- encoding:utf-8 -*-
from __future__ import print_function
import argparse
import datetime
import exifread
import flickrapi
import os
import sys
dependencies
virtualenv
http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html
sudo pip install vitualenvwrapper
in .bash_profile add (or create)
@peterlyeung
peterlyeung / sfdc.py
Created July 18, 2018 02:59
Lambda function to copy files from a SFTP server and add it to Salesforce as an attachment
import paramiko
import requests
import base64
import json
from simple_salesforce import Salesforce
#---------------------------------
# FTP portion
#---------------------------------
@steinwaywhw
steinwaywhw / AWS Lambda: Hello World.md
Last active March 8, 2022 10:40
An extremely simple AWS Lambda example in Python 3.

Preface

In general, AWS services can be accessed using

  1. AWS web interface,
  2. API libraries in a programming language, such as boto3 for Python 3,
  3. AWS command-line interface, i.e. awscli.

I opted for the API library since it is