Skip to content

Instantly share code, notes, and snippets.

"""
!!! Run tests by just typing 'python <this file>', not throw nosetests/your IDE
Before run these tests:
1) make sure that PhantomJS executable is in your PATH (type phantomjs in CLI)
for custom phantomjs location change PHANTOMJS_PATH
2) run app dev server and make sure that BASE_URL is equal to real URL
"""
import unittest
<?php
// in app/Providers/AppServiceProvider
/*namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{*/
public function boot()
{
if (\App::environment('local')) {
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
class UserProduct(Base):
user_id = Column(BigInteger, ForeignKey('user.user_id'),
primary_key=True)
product_id = Column(BigInteger, ForeignKey('product.product_id'),
primary_key=True)
class Product(Base):
product_id = Column(BigInteger, primary_key=True)
@absent1706
absent1706 / test_timeout.py
Created July 24, 2016 14:39
timeout decorator
import time
from timeout import timeout
class Test(object):
@timeout(2)
def test_a(self, foo, bar):
print foo
time.sleep(1)
print bar
return 'A Done'
@absent1706
absent1706 / keys.sublime-keymap
Created July 25, 2016 10:48
Sublime settings
[
{ "keys": ["alt+shift+f"], "command": "reindent" },
{ "keys": ["ctrl+alt+s"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+alt+p"], "command": "prompt_select_workspace" },
{"keys": [ "ctrl+alt+z" ], "command": "insert_snippet", "args": { "name": "Packages/User/my-snippets/localize.sublime-snippet"} },
]
@absent1706
absent1706 / activate.bat
Created July 27, 2016 10:38
GAE env files
@echo off
set "VIRTUAL_ENV=E:\Web.LOCAL\Python\projects\knowstory\env"
set "ROOT_DIR=E:\Web.LOCAL\Python\projects\knowstory"
if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
) else (
if not defined PROMPT (
set "PROMPT=$P$G"
)
@absent1706
absent1706 / composer.json
Last active August 2, 2016 09:59 — forked from spekkionu/composer.json
Standalone validation using laravel validation component
{
"require": {
"illuminate/validation": "~4.2.9"
},
}
// checks that all files in <input type="file"> have valid mime type (according to 'accept' attribute)
$.fn.filesHaveValidType = function() {
// this validation works for:
// 1. simple 'accept' values like 'image/*'
// 2. combined 'accept' values like accept="image/png, audio/mp3"
var elem = this[0];
var accept = this.attr('accept');
if (accept) {
var acceptTypes = accept.split(',').map(function(s) { return s.trim() });
// iterate over all files and return false if some file is of invalid type
@absent1706
absent1706 / framework.css
Created August 19, 2016 19:18
css-simple-bootstrap
/* Grid system */
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container:after, .container:before, .row:after, .row:before {
content: " "; display: table;
}
@absent1706
absent1706 / html-bootstrap-search-starter.html
Created August 26, 2016 21:01
boostrap starter page with search field in navbar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My project</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style type="text/css">
.navbar-avatar {
padding-top: 7px !important;
padding-bottom: 7px !important;