Skip to content

Instantly share code, notes, and snippets.

View spiechu's full-sized avatar

Dawid Spiechowicz spiechu

View GitHub Profile
const express = require('express');
const app = express();
// define app logging, middleware, view engine etc.
// make sure you
// npm install advanced-throttle --save
const Throttle = require('advanced-throttle');
// boring factory...
<?php
namespace MyProject\MyBundle;
class AsciiConverter implements StringProcessorInterface
{
/**
* {@inheritdoc}
*/
public function getProccessedString($string) {
<?php
$standardTasks = [
// nothing special here, take $val and return trimmed
'standardTrim' => function($val) {
return trim($val);
},
// this one is better, check string encoding and convert to ASCII counterpart
'convertToASCII' => function($val) {
<?php
interface CommonErrorCodes {
const ERR_STATUS_OK = 0;
const ERR_STATUS_NOT_FOUND = 1;
const ERR_STATUS_INVALID = 2;
const CHECK_ERR_PREFIX = 'ERR_';
}
@spiechu
spiechu / hashgenerator.scala
Last active January 2, 2016 07:39
My first sloppy steps into Scala. Check corresponding blog post at http://spiechu.pl/2014/01/05/computing-file-hashes-using-scala
// Typical Java package declaration.
package pl.spiechu.hashutils
// Typical class imports. More than one in curly brackets.
// Java classes work just fine in Scala.
import java.io.{ File, FileInputStream }
import java.security.MessageDigest
/**
* Singleton object. You cannot create an instance using 'new'.
@spiechu
spiechu / num_counter.dart
Created January 7, 2013 22:42
Gist is a part of blog entry at http://spiechu.pl/2013/01/07/pierwsze-kroki-z-dart/ [in Polish] Working version can be found at http://spiechu.pl/dart/num_counter.html
import 'dart:isolate';
import 'dart:html';
/**
* Isolate running asynchronously.
*/
void numCounter() {
port.receive((msg, replyTo) {
Element h1 = query("h1#counter${msg['id']}");
int counter = 0;
@spiechu
spiechu / icmp.php
Created May 11, 2012 18:39
Class ICMPPing constructs raw ICMP echo packet, sends it and echoes the response
<?php
// See the corresponding blog entries (in Polish):
// http://spiechu.pl/2012/05/16/tworzenie-pakietow-icmp-w-php
// http://spiechu.pl/2012/05/26/w-miare-bezpieczne-uruchamianie-skryptow-php-poprzez-shell_exec
class ICMPPing
{
const TYPE_REQUEST = 0x08;
const TYPE_RESPONSE = 0x00;
@spiechu
spiechu / storager.coffee
Created April 15, 2012 18:07
Just playing with CoffeeScript, jQuery and localStorage
$ ->
retrieveStoredFormFields = ->
# przejezdzam po wszystkich elementach formularza
# przeznaczonych do zapamietania
$('form .storeMe').each ->
# @ jest aliasem this
fieldValue = localStorage.getItem $(@).attr('id')
# jesli jest cos w localStorage to przypisuje elementowi formularza
if fieldValue then $(@).val fieldValue
@spiechu
spiechu / SpiechuCookieEncrypter.php
Created April 5, 2012 08:38
Class designed to encrypt and decrypt cookies along with some unit tests.
<?php
class SpiechuCookieEncrypter
{
const SEPARATOR = '(sep)';
protected $password = null;
protected $algorithm = null;
protected $mode = null;
public function __construct()
@spiechu
spiechu / shaker.py
Created September 28, 2011 19:54
Shaker launch script
#!/usr/bin/env python
import unicodedata
from numbers import Number
class Shaker:
def __init__(self, shakerCapacity = 1000000):
# Zakladamy, ze pojemnosc shakera jest nieograniczona ;-)