Skip to content

Instantly share code, notes, and snippets.

@bahattincinic
bahattincinic / gist:9671766
Created March 20, 2014 19:22
Angular Js Autocomplete Example
<!DOCTYPE html>
<html>
<head>
<title>Auto Complete Test</title>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('mainApp', []);
// Factory
@bahattincinic
bahattincinic / gist:9803841
Last active August 29, 2015 13:57
Fish Git Branch Name (~/.config/fish/config.fish)
function fish_prompt --description 'Write out the prompt'
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
if not set -q __git_cb
@bahattincinic
bahattincinic / gist:11248118
Last active August 29, 2015 14:00
Underscore adaptation of '_.where' for knockout
_.mixin({
koMatches: function (attrs) {
return function (obj) {
if (obj == null){
return _.isEmpty(attrs);
}
if (obj === attrs){
return true;
}
for (var key in attrs) {
@bahattincinic
bahattincinic / gist:11289745
Last active August 29, 2015 14:00
Permission control with KnockoutJs
function Permissions(){
var self = this;
/* Permissions */
self.permissions = ko.observableArray([]);
/*
* Set Permission
* @param{String} key
* @param{boolean} value
var myApp = angular.module('myApp', []);
// settings
myApp.constant('settings', {
apiEndpoint: '/api/v1',
node: 'http://domain.com:8888',
});
// controller
myApp.controller('MyCtrl', ['$scope', 'settings', function($scope, settings){
@bahattincinic
bahattincinic / gist:ad507eda7e940dacc99b
Last active August 29, 2015 14:00
Environment Specific Configuration In AngularJS
var mainApp = angular.module('myApp', []);
mainApp.service('ConfigService', function (){
var _environments = {
local: {
host: ['l', 'localhost'],
config: {
api_endpoint: '/api/v1',
node_url: 'http://localhost:9998'
}
@bahattincinic
bahattincinic / gist:8a253d08b428b127f5ca
Last active August 29, 2015 14:01
Knockout Js Custom Subscribe
ko.subscribable.fn.subscribeChanged = function (callback, target) {
var oldValue;
this.subscribe(function (_oldValue) {
oldValue = _oldValue;
}, target, 'beforeChange');
this.subscribe(function (newValue) {
callback(newValue, oldValue, this);
}, target);
};
@bahattincinic
bahattincinic / gist:5a8399ac0ca6d911c374
Last active December 13, 2019 06:38
Firebase & Knockout Realtime Monitoring
<!DOCTYPE html>
<html>
<head>
<title>Firebase & Knockout Test</title>
<link rel="stylesheet" type="text/css"
href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
<script type="text/javascript"
src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
@bahattincinic
bahattincinic / gist:164a615fc1ef43c2f748
Last active August 29, 2015 14:06
Updating PagingToolbar on ExtJs Filter (Version 3)
var store = new Ext.data.JsonStore({root: "data", url: "<url>", totalProperty: 'totalCount', idProperty: 'id',method: 'POST', fields:[]});
var page = new Ext.PagingToolbar({pageSize: 25, store: store});
var grid = new Ext.grid.GridPanel({store: store, tbar: page});
store.load({params:{start:0, limit:25}});
grid.render('#exapmle');
grid.on('filterupdate', function(){
var o = {}, pn = this.store.paramNames;
o[pn.start] = 0;