Skip to content

Instantly share code, notes, and snippets.

View iaintshine's full-sized avatar

Boguslaw Mista iaintshine

View GitHub Profile
@iaintshine
iaintshine / c_erlang
Created February 8, 2013 23:49
Comparison between C style for loop and Erlang on a sum function example
//
// C - style
//
int sum( int boundary )
{
int i, sum = 0;
for( i = 1; i <= boundary; i++ )
sum += 1;
#pragma once
template<typename T>
class Singleton
{
public:
template<typename... Args>
static
T* GetInstance( Args... args )
@iaintshine
iaintshine / echo.erl
Created February 13, 2013 01:17
Erlang echo example
-module(echo).
-compile(export_all).
go() ->
register(echo, spawn(echo, loop, [])),
echo ! { self(), hello },
receive
{ _Pid, Msg } ->
io:format("~w~n", [Msg])
end,
@iaintshine
iaintshine / inheritance.hpp
Created February 24, 2013 14:50
Cross platform shit
#pragma once
//
// Abstract interface
//
class IFile
{
public:
virtual ~IFile() = 0;
@iaintshine
iaintshine / query.erl
Last active December 14, 2015 23:49
Query List Comprehesion compared to Active Record
mnesia:transaction(
fun() ->
qlc:e(
qlc:q( [ { U#name, U#reputation } ||
U <- mnesia:table(users),
U#user.age < 21])
)
end
)
@iaintshine
iaintshine / examples_controller.rb
Created April 25, 2013 22:47
Basic authentication only in production environment
class ExamplesController < ApplicationController
before_filter :authenticate_ip if Rails.env.production?
http_basic_authenticate_with :name => "login", :password => "pass" if Rails.env.production?
end
@iaintshine
iaintshine / pretty_print.rb
Last active December 30, 2015 00:39
Rack middleware for pretty printing json responses and sample Rails usage
require 'rack'
module Rack
class PrettyPrint
def initialize(app, options = {})
@app, @options = app, options
end
def call(env)
status, headers, response = @app.call(env)
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"runtime"
"sync"
"time"
@iaintshine
iaintshine / palindrome.rb
Created August 13, 2014 16:14
A Ruby program which checks command line arguments if they are palindromes
#!/usr/bin/env ruby
# palindrome.rb
module Palindrome
ALPHABET = ('a'..'z').to_a + ('A'..'Z').to_a
def palindrome?
normalized == normalized.reverse
end
@iaintshine
iaintshine / boot.js
Created August 13, 2014 16:20 — forked from jdx/boot.js
// This script will boot app.js with the number of workers
// specified in WORKER_COUNT.
//
// The master will respond to SIGHUP, which will trigger
// restarting all the workers and reloading the app.
var cluster = require('cluster');
var workerCount = process.env.WORKER_COUNT || 2;
// Defines what each worker needs to run