Skip to content

Instantly share code, notes, and snippets.

@iamdionysus
iamdionysus / flask_pywsgi_websocket_reloader.py
Created November 14, 2013 05:49
Flask + websocket from gevent.pywsgi + reloader. I wanted to use Flask for the micro web platform. Added websocket from gevent which needs pywsgi instead of wsgi Finally, for agile development, change should be made on the fly. Code snippet for werkzeug.serving is using gevent.wsgi instead of gevent.pywsgi. If you follow the snippet it causes th…
from gevent import monkey; monkey.patch_all()
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template
import werkzeug.serving
app = Flask(__name__)
@app.route('/')
def index():
$ ssh-keygen -t rsa
$ scp ~/.ssh/id_rsa.pub user@git.repo:id_rsa.tmp
$ ssh user@git.repo
$ cat id_rsa.tmp >> .ssh/authorized_keys
@iamdionysus
iamdionysus / git_setup.sh
Last active December 31, 2015 16:49
git set up
# generate public private key to avoid typing password every time
ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub user@address:id_rsa.tmp
ssh user@address
cat id_rsa.tmp >> .ssh/authorized_keys
exit
# local git initilization
@iamdionysus
iamdionysus / post-receive
Created February 25, 2014 13:27
post-receive hook under /hooks in order to automate deploy on the server master branch. git push origin master invokes post-receive hook below after the push has been done. Then the code below will be executed which make repository on a server pull the change automatically.
#!/bin/sh
unset GIT_DIR
cd /my/git/project/on/server && git pull origin master
@iamdionysus
iamdionysus / WebClientTrick.cs
Created April 1, 2014 22:57
two points when using System.Net.WebClient
using (var web = new WebClient())
{
web.Encoding = System.Text.Encoding.UTF8;
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
}
@iamdionysus
iamdionysus / how-to-make-pry-work-with-inf-ruby.md
Created June 6, 2014 02:56
backup for the how to make pry work with inf-ruby

At least from my experience and set up, this is not a proper way to make pry work under emacs 24.3 and current inf-ruby with MEPLA installation. Since this gist shows up quite high in google search result, I'd like to comment here what was the problem and how I solved it.

Issues

  • (add-to-list 'inf-ruby-implementations '("pry" . "pry")) causes init.el load error. It's already implemented in the inf-ruby.el source so I don't think it's necessary to add again.

  • (setq inf-ruby-default-implementation "pry") actually makes inf-ruby run the pry. However, with flaws. If pry is running with this set up and if I send the buffer/region/block, I get NameError: uninitialized constant IRB from (pry):1:in `__pry___'. Again, I looked into the inf-ruby.el source code and it looks like inf-ruby is already taking care of the pry smartly. So this set up shouldn't be added to init.el as well.

Solution

  • don't add anything which is mentioned above to init.el to make pry work especially if it's in
@iamdionysus
iamdionysus / how-to-make-passenger-work-with-rails-4-1.md
Last active August 29, 2015 14:02
How to make passenger work with rails 4.1

Issue

rails 4.1 production setting uses secret_key_base by reading values from the environment for security reason. If ENV["SECRET_KEY_BASE"] doesn't exist nginx + passenger will raise error. You can simply set up envrionment variable in the shell, but under rvm, it sometimes gets tricky.

Solution

Use figaro gem and set it up

  • Gemfile, add gem 'figaro' and bundle update
  • figaro install : this does
    • create config/application.yml
    • append .gitignore
  • config/application.yml, add SECRET_KEY_BASE: your_key
@iamdionysus
iamdionysus / install-recent-ghc.md
Created June 20, 2014 00:50
How to install recent ghc and cabal for ubunt 12.04 by adding ppa

Add apt-repository, install ghc and cabal

I used this repository.

sudo add-apt-repository ppa:hvr/ghc
sudo apt-get install ghc-7.8.3
sudo apt-get install cabal-install-1.20

Add the bin directory to PATH

The packages install into /opt/ghc/$VER and /opt/cabal/$VER respectively. If you use zsh, make sure to add to bash settings as well. In Emacs haskell-mode, when hasekll-interactive-bring command tries to load ghci, the PATH envrionment seems to be under bash. Save the settings and test.

Sub test_set_table()
ActiveDocument.Tables(4).Cell(1, 1).Range.Text = "Blah"
End Sub
Sub test_get_http()
Dim result As String
Dim myURL As String
@iamdionysus
iamdionysus / copy_paste_win32ole_excel.rb
Last active August 29, 2015 14:18
ruby win32ole copy and paste last row in excel
excel = WIN32OLE.new 'Excel.Application'
excel.visible = true
workbook = excel.Workbooks.open "path/to/file"
sheet = workbook.Worksheets 1
def excel_copy_and_paste_last_row excel, workbook, sheet
last_row = sheet.UsedRange.Rows.Count
sheet.Rows(last_row).copy
sheet.Cells(last_row + 1, 1).Select