Skip to content

Instantly share code, notes, and snippets.

mike@rbci:~$ psql -U postgres
psql (9.0.3)
Type "help" for help.
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0".
template0=# update pg_database set datistemplate = FALSE where datname = 'template1';
UPDATE 1
@moniyax
moniyax / resize.bash
Created July 31, 2013 11:42
Bash script for resizing images with imagemagick
for X in *.{jpg,png}; do convert "$X" -resize 602x400 -strip -quality 86 "$X"; done
@moniyax
moniyax / my_enum.rb
Last active December 20, 2015 06:39
Simple demo implementation of enumerators in Ruby using fibers.
class MyEnum
def initialize fiber
@f = fiber
end
def next
@f.resume
end
end
@moniyax
moniyax / matcher.spec
Created July 14, 2013 21:41
Custom RSpec Matcher Example
RSpec::Matchers.define :have_more_numbers_than do |arg|
match do |obj|
obj.scan(/\d/).length > arg.scan(/\d/).length
end
end
describe "my matching" do
it { "555555foo9".should have_more_numbers_than "jk444" }
end
Tourney = window.Tourney or {}
# Views
Tourney.AppView = Backbone.View.extend
el: "#app"
initialize : ->
Groups.on "reset", @buildTables, this
Groups.on "reset", @buildFixtures, this
@moniyax
moniyax / quick_dirty_server.rb
Last active December 16, 2015 03:18
Playing with TCP and HTTP
require "socket"
puts 'QuickDirty web server (v0.0.0 codename Mire)'
puts 'Listening on 0.0.0.0:7776, CTRL+C to stop'
Socket.tcp_server_loop(7776) do |conn|
puts "Successfully connected"
req = conn.gets("\r\n\r\n")
puts req
@moniyax
moniyax / CakeFile.coffee
Created March 19, 2013 14:25
Basic Cakefile for compiling coffescript files
fs = require 'fs'
{print} = require 'util'
{spawn} = require 'child_process'
build = (callback) ->
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
<html>
<head>
<meta charset="UTF-8">
<title>index.html</title>
<style type="text/css">
input[type="radio"] {
margin: 0;
}
.switcher-wrap{
function ang2(ang1, n1, n2){
return rad_to_deg(Math.asin(Math.sin(deg_to_rad(ang1)) * n1 / n2))
}
function n2(ang1, ang2, n1){
return n1 * Math.sin(ang1) / Math.sin(ang2)
}
function deg_to_rad(ang){
return ang * 22 / 7.0 / 180
def ang2(ang1, n1, n2)
rad_to_deg Math.asin(Math.sin(deg_to_rad(ang1)) * n1 / n2.to_f)
end
def deg_to_rad(ang)
ang * 22 / 7.0 / 180
end
def rad_to_deg(ang)
ang * 180 * 7.0 / 22