Skip to content

Instantly share code, notes, and snippets.

@absent1706
absent1706 / js-form-hacks.js
Last active February 1, 2017 14:37
JS form hacks: reset button, clean empty fields
/*
* Handler for reset button that cleans all form fields and submits form
* See http://www.javascript-coder.com/javascript-form/javascript-reset-form.phtml
*/
$('.js-reset-closest-form').click(function() {
var form = $(this).closest('form')[0];
/* it's important to take form.elements, not just $(form).find(input)
* because inputs can be OUTSIDE <form> tag, i.g.:
* <form id="search-form"> ... </form>
* ...
@absent1706
absent1706 / example.html
Last active July 24, 2021 12:10
Bootstrap-collapse rotate icon. https://jsfiddle.net/1L3xy40k/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
[data-toggle="collapse"][aria-expanded="true"] > .js-rotate-if-collapsed
{
-webkit-transform: rotate(180deg);
@absent1706
absent1706 / config.php
Created January 11, 2017 13:27
psysh/config.php
<?php
/*
PsySh config file (see http://psysh.org/#configure)
!!!
Copy this file to ~\.config\psysh\config.php, where ~ is your home dir
for example (Windows): C:\Users\MY_USER\.config\psysh\config.php
Result dump will look like http://www.qopy.me/D6R2fYEQSw6wjV7NDaPMxw
*/
@absent1706
absent1706 / activate.bat
Last active March 2, 2017 11:25
knowstory-env
@echo off
set "ROOT_DIR=E:\code\knowstory"
set "VIRTUAL_ENV=%ROOT_DIR%\env"
if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
) else (#!E:\Python\python.exe
import re
import sys
@absent1706
absent1706 / sqlalchemy-truncate_db.py
Last active April 5, 2023 03:50
Sqlalchemy: Truncate all tables
def truncate_db(engine):
# delete all table data (but keep tables)
# we do cleanup before test 'cause if previous test errored,
# DB can contain dust
meta = MetaData(bind=engine, reflect=True)
con = engine.connect()
trans = con.begin()
con.execute('SET FOREIGN_KEY_CHECKS = 0;')
for table in meta.sorted_tables:
con.execute(table.delete())
@absent1706
absent1706 / php-reflect-private-properties.php
Created November 14, 2016 12:17
PHP: Reflect provate properties
<?php
/* Returns all properties og object including private/protected
* in [prop => value] array
*/
function props($obj) {
$reflect = new \ReflectionClass($obj);
$props = $reflect->getProperties();
$result = [];
foreach ($props as $prop) {
@absent1706
absent1706 / config-symfony.php
Last active November 14, 2016 15:03
PsySH config file which teaches PsySH how to dump Eloquent model and collection (http://www.qopy.me/D6R2fYEQSw6wjV7NDaPMxw)
<?php
/*
PsySh config file (see http://psysh.org/#configure)
!!!
Copy this file to ~\.config\psysh\config.php, where ~ is your home dir
for example (Windows): C:\Users\MY_USER\.config\psysh\config.php
Result dump will look like http://www.qopy.me/D6R2fYEQSw6wjV7NDaPMxw
*/
@absent1706
absent1706 / db.sql
Last active October 18, 2016 15:22
Select products with grade order between grade_from and grade_to ( grade_from_id and grade_to_id can be nulls)
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 10.1.8-MariaDB - mariadb.org binary distribution
-- Server OS: Win32
-- HeidiSQL Version: 9.3.0.4984
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
import re
from cgi import escape
def index(environ, start_response):
"""This function will be mounted on "/" and display a link
to the hello world page."""
start_response('200 OK', [('Content-Type', 'text/html')])
return ['''Hello World Application
This is the Hello World application:
@absent1706
absent1706 / api.py
Last active September 26, 2016 14:58
python-gae-api-oauth-no-servie-account
'''
code is taken from
https://github.com/GoogleCloudPlatform/storage-file-transfer-json-python
'''
from server.settings import current_environment as env
from server.errors import InternalError
import httplib2
from apiclient.discovery import build as discovery_build
from oauth2client.file import Storage as CredentialStorage