Skip to content

Instantly share code, notes, and snippets.

@graingert
graingert / client.py
Created Sep 3, 2021 — forked from foxmask/client.py
websocket client
View client.py
#!/usr/bin/env python3
import sys
import asyncio
import json
import websockets
async def hello():
uri = "ws://localhost:8888"
@graingert
graingert / repl.scala
Created Dec 20, 2017 — forked from fedesilva/repl.scala
Voldemort types in scala
View repl.scala
f@omoikane:~$ scala
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :load Workshop/mine/scala-misc/voldemort.scala
Loading Workshop/mine/scala-misc/voldemort.scala...
defined module Dungeon
scala> val nemesis = Dungeon curse "fedesilva"
View ajaxcall.js
map.on('click', function(event){
var x1_wgs;
var y1_wgs;
async function ajax(x,y){
const data = $.ajax({
url:'/geocoding/egsa_2_wgs.php?x='+x+'&y='+y,
async:true,
type:'GET',
@graingert
graingert / Dockerfile
Created Jun 26, 2017 — forked from tabiodun/Dockerfile
Dockerfile for tabiodun/selenium-chrome-headless
View Dockerfile
FROM selenium/node-base:3.4.0-dysprosium
USER root
ARG CHROME_VERSION="google-chrome-beta"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install \
@graingert
graingert / gist:bf23f6f4193679272307cc2c1ac1e763
Created May 15, 2017 — forked from colin-kiegel/gist:b35d278d6ed5251dfa85
regex replace multi-line + in multiple files
View gist:bf23f6f4193679272307cc2c1ac1e763
$FILES="*.rs"
$REGEX="s#(.*)\n(.*)/\2\n\1/"
find . -name "$FILES" | xargs perl -0777 -pi -e '$REGEX'
# flag: -0777 tells perl to read the file as a whole
# replace '-pi' with '-pi.bak' to create backups
View EitherReadsExample.scala
import JsEither._
case class Page(id: Int, name: String, screen_name: String, is_closed: Int, photo_50: String, photo_100: String, photo_200: String)
object Page {
implicit val format = Json.format[Page]
}
case class Profile(id: Int, first_name: String, last_name: String)
object Profile {
implicit val format = Json.format[Profile]
View highcharts-jsdom.js
/**
* Sample of serverside generation of Highcharts using an extension to jsdom in node.js.
*
* Usage:
* npm install jsdom
* npm install highcharts
* node highcharts-jsdom
*/
/* eslint-env node */
@graingert
graingert / dataURItoBlob.js
Created Apr 27, 2016 — forked from davoclavo/dataURItoBlob.js
Convert dataURI to Blob so large images do not crash the browser. Based on: http://stackoverflow.com/questions/10412299 and http://stackoverflow.com/questions/6850276
View dataURItoBlob.js
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var arrayBuffer = new ArrayBuffer(byteString.length);
var _ia = new Uint8Array(arrayBuffer);
@graingert
graingert / README.md
Created Apr 13, 2016 — forked from smileart/README.md
My ZSH Theme — Agnoster Mod
View README.md

My modified fork of agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

Compatibility

View graph.py
numpy.genfromtxt(path, delimiter=',', names=True, dtype=None)
fig = plt.figure(1)
plt.xlabel('Month')
plt.ylabel('Cost of Food')
plt.title('Cost of Food from May 2013 to May 2014)
# month is a tuple I created for this data, month[0] is number of month, month[1] is numpy array
plt.plot_date([month[0] for month in data], [month[1][0][plan] for month in data], '-b', label=month[1][0][1])