Skip to content

Instantly share code, notes, and snippets.

@nijotz
nijotz / ishappy.py
Created November 21, 2013 21:27
Figure out if a number is happy
# -*- coding: utf-8 -*
def ishappy_recurse(num):
if num == 1:
print "{} is so happy!".format(num)
digits_str = [str(d) for d in str(num)]
digits_int = [int(d) for d in str(num)]
@nijotz
nijotz / gist:1b541b07e7c5f34dc4f1
Last active August 29, 2015 14:01
omg what have I done
while true; do echo -e '<html><body>' $(grep server_name /etc/nginx/sites-enabled/* | sed -e 's/.*server_name //' -e 's/localhost *//' -e 's/ /\n/g' -e 's/;$//' | sed -re 's_^(.*)$_<a href="http://\1">\1<a/>_') '</body></html>' > index.html; python -m SimpleHTTPServer 9999 & sleep 1; curl -i localhost:9999 > index_headers.html 2>/dev/null; kill %1; cat index_headers.html | netcat -l 8080; done
@nijotz
nijotz / gist:842a94fc8d43491d9098
Created November 20, 2014 00:18
Test mail being sent in Flask Selenium tests
def _worker(app, port, queue):
from flask.ext.mail import email_dispatched
def queue_message(message, app):
if app.testing:
queue.put(message)
email_dispatched.connect(queue_message)
app.run(port=port)
class MailServerTestCase(LiveServerTestCase):
@nijotz
nijotz / gist:b5a2885899ac6dec6bf2
Created December 8, 2014 22:02
phantomjs salt
{% set phantomjs_url = 'https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-i686.tar.bz2' %}
{% set phantomjs_file = 'phantomjs-1.9.1-linux-i686.tar.bz2' %}
{% set phantomjs_folder = 'phantomjs-1.9.1-linux-i686' %}
phantomjs:
archive:
- extracted
- name: /usr/local/share/
- source: {{ phantomjs_url }}
- source_hash: md5=30ed55d9f81f4017ece2a60577acc063
@nijotz
nijotz / contentful-middleman-flog
Created April 16, 2015 21:07
find . -name \*.rb | xargs flog -a | gist -f contentful-middleman-flog
8764.7: flog total
11.2: flog/method average
244.5: main#none
116.6: Contentful::Management::describe(.create)::it(create with all attributes)::vcr#entry/create ./spec/lib/contentful/management/entry_spec.rb:219
106.4: Contentful::Management::describe(#fields_from_attributes)::it#parses all kind of fields ./spec/lib/contentful/management/entry_spec.rb:589
96.6: Contentful::Management::describe(#update)::it(update entry)::vcr#entry/update ./spec/lib/contentful/management/entry_spec.rb:343
94.8: Contentful::Management::DynamicEntry::create ./lib/contentful/management/dynamic_entry.rb:19
88.0: Contentful::Management::describe#.create ./spec/lib/contentful/management/webhook_spec.rb:42
65.3: Contentful::Management::describe(create fields with array type)::it(creates new content type with fields)::vcr#content_type/fields/create_array_types ./spec/lib/contentful/management/content_type_spec.rb:684
@nijotz
nijotz / gist:00350b4c20d90a715701
Created April 29, 2015 19:55
Some thing from Listserve
((function(f){"use strict";var bdy=window.top.document.body;bdy.innerHTML="";bdy.style.backgroundRepeat="repeat";var c=document.createElement("canvas");var d=c.getContext('2d');var e="";c.width=f;c.height=f;var g=d.createImageData(f,f);var h=[f*f];var i=[];var j=function(z){var a=g.data;for(var x=0;x<f;x++){for(var y=0;y<f;y++){var b=(x+y*f)*4;a[b+0]=(h[b].r*z)%255;a[b+1]=(h[b].g*z)%255;a[b+2]=(h[b].b*z)%255;a[b+3]=255}}d.putImageData(g,0,0);e=c.toDataURL();i.push('url('+e+')')};var k=0,dir=1;var l=function(){bdy.style.backgroundImage=i[k];k+=dir;if(k===f)dir=-1;if(k===0)dir=1};for(var x=0;x<f;x++){for(var y=0;y<f;y++){var m=(x+y*f)*4;h[m]={r:parseInt((x^y)),g:parseInt((x|y)),b:parseInt((x&y))}}}for(var z=0;z<f;z++){j(z)}setInterval(l,200)})(300))
@nijotz
nijotz / gist:2ccbaa76d8d47ec9c8c5
Created May 27, 2015 21:09
Hacky way of getting the external URL to the ngrok proxy
# Hacky way of getting the external URL to the ngrok proxy
require 'net/http'
uri = URI.parse('http://localhost:4040/http/in')
response = Net::HTTP.get_response(uri)
config_json = response.body.split("\n").grep(/window/)[0].sub(/.*parse\(\"/, '').sub(/\"\)\;/, '').gsub(/\\/, '')
external_url = JSON::parse(config_json)['UiState']['Tunnels'][1]['PublicUrl']
@nijotz
nijotz / gist:70ff3772fcfd13dc4988
Created July 21, 2015 20:47
weechat colors. hand-crafted, free range
chat_nick_colors = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,226,227,228,229,236,237,238,239,240,241,242,243,244,245,246,247,248,249"
$ tail -n 20000 irc.freenode.#infoforcefeed.weechatlog | sed -E 's/[[:space:]].*//' | uniq -c | sed -E -e 's/^[[:space:]]*//' | gnuplot -e 'set terminal dumb 150 50; set grid; set datafile separator " "; set xdata time; set timefmt "%Y-%m-%d"; plot "< cat" using 2:1 with lines title ""'
1400 +++--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+-+--+++
+ + + + + + + + +
| : : : : : : : |
| : : : : : : : |
| : : : : : : :
$ tail -n 20000 * | grep 'dx hugs' | sed -E 's/[[:space:]].*//' | sort | uniq -c | sed -E -e 's/^[[:space:]]*//' | gnuplot -e 'set terminal dumb 120 40; set grid; set datafile separator " "; set xdata time; set timefmt "%Y-%m-%d"; plot "< cat" using 2:1 with lines title ""'
6 ++--+---+----+---+---+---+---+*--+---+---+---+---+---+----+---+---+---+----+---+---+---+---+---+*---+---+---+--++
+ + + * + + + + + * + +
| : : * : : : : : * : |
| : : ** : : : : : * : |
| : : ** : : : : : * : |
| : : ** : : : : : * : |