Skip to content

Instantly share code, notes, and snippets.

/*
* A rather simple way of testing out SwampDragon.
* Create a load of connections, connect, subscriber, update and count the number
* of published messages.
*
* SETUP:
* 1. npm install sockjs-client-node
* 2. curl https://raw.githubusercontent.com/jonashagstedt/swampdragon/master/swampdragon/static/swampdragon/js/swampdragon.js > swampdragon.js
* 3. Set router_name to the name of your router.
* 4. Change "sd.update_object(router_name, { value: val }, 'foo');" to call
@drincruz
drincruz / anagram.py
Created August 17, 2014 15:53
Simple example to find out if two strings are anagrams of each other
#!/usr/bin/env python
"""
Example of how you can test if strings are anagrams
"""
def is_anagram(str1, str2):
"""
Check if str1 is an anagram of str2
@kelvinn
kelvinn / cmd.sh
Created July 24, 2014 02:55
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 4, 2025 21:20
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@premit
premit / imdb_next_page_spider.py
Created July 23, 2014 14:14
Scrapy reference: Crawling next pagination
'''
Spider for IMDb
- Retrieve most popular movies & TV series with rating of 8.0 and above
- Crawl next pages recursively
'''
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
@codehack
codehack / iso8601.py
Created June 26, 2014 19:29
ISO8601 date time parser for Python using regex package
#!/usr/bin/python
import re
# i think i missed a couple of things in 8601 but this should cover 98% of cases.
iso8601 = re.compile(r'^(?P<full>((?P<year>\d{4})([/-]?(?P<mon>(0[1-9])|(1[012]))([/-]?(?P<mday>(0[1-9])|([12]\d)|(3[01])))?)?(?:T(?P<hour>([01][0-9])|(?:2[0123]))(\:?(?P<min>[0-5][0-9])(\:?(?P<sec>[0-5][0-9]([\,\.]\d{1,10})?))?)?(?:Z|([\-+](?:([01][0-9])|(?:2[0123]))(\:?(?:[0-5][0-9]))?))?)?))$')
# to perform the actual date match
m = iso8601.match('2014-12-05T12:30:45.123456-05:30')
@sebdah
sebdah / forms.py
Created June 24, 2014 13:25
Handling unique_together errors in Django forms
class MyModelForm(ModelForm):
class Meta:
model = MyModel
fields = ('field2', 'field3', 'field4', 'field5')
def clean(self):
"""
Clean MyModel
"""
# Get the cleaned data
@maxim
maxim / tasks.yml
Last active June 15, 2016 03:41
Copy file on remote machine in ansible
- name: ensure file exists at path
shell: rsync -ci /source/path /destination/path
register: rsync_result
changed_when: "rsync_result.stdout != ''"
@makmanalp
makmanalp / sshtest-playbook.yml
Last active June 18, 2021 15:06
SSH agent forwarding tester for ansible / vagrant
---
- hosts: all
sudo: no
tasks:
- shell: echo "Client= [$SSH_CLIENT] Sock= [$SSH_AUTH_SOCK]"
register: myecho
- debug: msg="{{myecho.stdout}}"
- shell: ssh-add -l
register: myecho
- debug: msg="{{myecho.stdout}}"
@willmendesneto
willmendesneto / Gruntfile.js
Last active August 29, 2015 14:01
Files requireds for create a project for create angular modules using Grunt task manager
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
// OBS:
// Replace the string with informations