Skip to content

Instantly share code, notes, and snippets.

View jawache's full-sized avatar

Asim Hussain jawache

View GitHub Profile
@simonaco
simonaco / index.js
Last active February 14, 2019 15:53
const MongoClient = require('mongodb').MongoClient;
// Initialize authentication details required for database connection
const auth = {
user: process.env.user,
password: process.env.password
};
// Initialize global variable to store database connection for reuse in future calls
let db = null;
const loadDB = async () => {
// If database client exists, reuse it
@Bouke
Bouke / gist:10454272
Last active September 22, 2023 17:23
Install FreeTDS, unixODBC and pyodbc on OS X

First, install the following libraries:

$ brew install unixodbc
$ brew install freetds --with-unixodbc

FreeTDS should already work now, without configuration:

$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"

locale charset is "UTF-8"

@malixsys
malixsys / app.scss
Last active July 11, 2016 07:42
ionic framework validation
form i.icon.error {
color: $assertive;
}
form input + i.icon.error {
display: none;
margin-left: 8px;
}
form.ng-submitted input.ng-invalid + i.icon.error {
@guillaumepiot
guillaumepiot / gist:3939452
Created October 23, 2012 15:28
ANGULARJS - Django CSRF Token header setup
var myApp = angular.module('myApp').config(function($httpProvider) {
$httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val();
});
@tokumine
tokumine / window_rank.sql
Created January 9, 2012 16:30
calculating windowed rank in postgresql for a scoreboard or leaderboard
-- this SQL can be used to calculate the rank of a given user in a game,
-- and the names/scores of those just above and below him.
-- This is useful in online games or citizen science projects where you
-- just want to see the 'proximity' of other users around you, not the entire global rank
-- I want to find the rank and score for user_3, and other users 3 above and 3 below.
WITH global_rank AS (
SELECT name, score, rank() OVER (ORDER BY score DESC) FROM scores
)
SELECT * FROM global_rank
@dcramer
dcramer / track_data.py
Created December 6, 2010 19:15
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')