Skip to content

Instantly share code, notes, and snippets.

View daGrevis's full-sized avatar
⌨️
Keyboard operator

Raitis Stengrevics daGrevis

⌨️
Keyboard operator
View GitHub Profile
@daGrevis
daGrevis / simple_sign_in_and_sign_out.py
Created April 20, 2012 08:50
Simple sign in and sign out in Python's Flask
from flask import Flask, session, escape, request, redirect, url_for
from os import urandom
app = Flask(__name__)
app.debug = True
app.secret_key = urandom(24)
@app.route('/')
@daGrevis
daGrevis / weird.js
Created April 25, 2012 12:02
Weird JS
if ('0') { // Prints 'true'.
console.log('true');
} else {
console.log('false');
}
@daGrevis
daGrevis / string_format.js
Created May 2, 2012 12:49
String format in JavaScript
String.prototype.format = function () {
var g = this.toString();
if (!arguments.length) return g;
var c = "string" == typeof arguments[0] ? arguments : arguments[0],
e;
for (e in c) g = g.replace(RegExp("\\{" + e + "\\}", "gi"), c[e]);
return g
};
@daGrevis
daGrevis / conf.php
Created May 7, 2012 07:14
Conf.php (simple example)
<?php
class Conf {
private $_storage = array();
function load($name) {
$this->_storage = require $name.'.php';
@daGrevis
daGrevis / bookmarklets_boilerplate.js
Created May 8, 2012 14:15
Bookmarklets boilerplate
javascript:void(function(){var jsCode=document.createElement('script');jsCode.setAttribute('src','http://example.com/script.js');document.body.appendChild(jsCode);}());
@daGrevis
daGrevis / jeffrey.py
Created May 8, 2012 19:11
Counts words in the file
import sys, re
if len(sys.argv) == 1:
exit()
with open(sys.argv[1]) as f:
content = f.read()
chunks = re.findall(r'\w+', content)
print('Count:', len(chunks))
@daGrevis
daGrevis / backloop.js
Created May 9, 2012 14:30
Creative programmer
for (var i = 10; i > 0; --i) {
console.log('Hello, world!');
}
@daGrevis
daGrevis / char_math.c
Created May 15, 2012 12:19
Char math
#include <stdio.h>
int main(int argc, char *argv[]) {
char foo = 'C';
char bar = 'A';
puts(foo - bar);
return 0;
@daGrevis
daGrevis / boilerplate.html
Created May 18, 2012 07:56
HTML5 Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5 Boilerplate</title>
<!--<link rel="stylesheet" href="common.css" />-->
@daGrevis
daGrevis / utc_offset.txt
Created May 23, 2012 11:26
List of time zones by UTC offset
-12:00
-11:00
-10:00
-09:30
-09:00
-08:00
-07:00
-06:00
-05:00
-04:30