Skip to content

Instantly share code, notes, and snippets.

@tborychowski
tborychowski / js-inheritance.js
Created October 14, 2014 09:19
JS inheritance
if (!Function.prototype.bind) {
Function.prototype.bind = function (context) {
if (typeof this !== 'function') throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
var args = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fn = function () {},
fBound = function () {
return fToBind.apply(this instanceof fn && context ? this : context,
args.concat(Array.prototype.slice.call(arguments)));
};
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[merge]
tool = winmerge
[mergetool "winmerge"]
name = WinMerge
<form class="form">
<input type="text" placeholder="enter text" name="name" value="">
<input type="checkbox" name="check">
<select name="select"><option value="select1">one</option><option value="select2">two</option></select>
<input name="radio" type="radio" value="radio1">
<input name="radio" type="radio" value="radio2">
</form>
<button class="start">Observe</button>
<button class="stop">Stop observing</button>
@tborychowski
tborychowski / numberFormat.js
Created March 6, 2012 21:47
JS :: Format a number
/**
* Formats numbers (or string numbers)
* @param number int or int-parsable string
* @param prec decimal precision
* @returns formatted number as string
*/
numberFormat : function (number, prec) {
var ext, name, numS, rgx = /(\d+)(\d{3})/;
number = number || '0';
prec = prec || 0;
@tborychowski
tborychowski / _lib.less
Created September 28, 2012 09:03
LESS :: _lib - mix-in library
/**
* LESS mix-in library
* vendor prefixes verified with prefixr.com and caniuse.com [2012-09-28]
* https://gist.github.com/3798764
*/
@img-base: "../img";
@icon-base: "../img/icons";
.b(@v) when (@v = 0) { font-weight: normal; }
@tborychowski
tborychowski / js-array-remove.js
Created October 10, 2012 10:33 — forked from danro/js-array-remove.js
JS :: Array Remove
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
@tborychowski
tborychowski / import_sql_file_to_db.php
Created October 11, 2012 14:13
PHP :: Import SQL file to DB
// import sql file
$file_content = file('updates.sql');
$query = "";
foreach($file_content as $sql_line){
if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
$query .= $sql_line;
if (substr(rtrim($query), -1) == ';'){
$result = $dbo->dbEdit($query);
echo $query.'<br>Result: '.($result==1?'OK':$result).'<br><br><br>';
$query = "";
@tborychowski
tborychowski / form_validation.js
Last active October 11, 2015 14:28
JS :: Simple form validation
function validate(f,v,a,x){
for(a=0;x=f[a++];)
if((v=window[x.getAttribute('valid')])&&!v(x.value)){
alert(x.getAttribute('alert'));
return !x.focus();
}
}
function notempty(x){return x>''}
function ismail(e){return /^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e)}
@tborychowski
tborychowski / quick-string.js
Created November 28, 2012 13:10
JS :: Quickly create a string of dots
new Array(20).join('.')
@tborychowski
tborychowski / user-location.js
Created August 22, 2014 12:56
JS :: user location
$.ajax({ url: '//www.google.com/jsapi', dataType: 'script' }).done(function () {
var addr = google.loader.ClientLocation.address;
console.log(addr);
});
$.getJSON('//freegeoip.net/json/', function(location) {
console.log(location);
});