Skip to content

Instantly share code, notes, and snippets.

View hsnaydd's full-sized avatar

Hasan Aydoğdu hsnaydd

View GitHub Profile
[
{
"name": "awaiting: API",
"color": "c2e0c6"
},
{
"name": "awaiting: decision",
"color": "bfd4f2"
},
{
@hsnaydd
hsnaydd / es6-ajax-request.js
Created March 7, 2016 11:52
Es6 Ajax request
export default class Ajax {
get(url, callback) {
let xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xhr.open('GET', url);
xhr.onreadystatechange = () => {
if (xhr.readyState > 3 && xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
@hsnaydd
hsnaydd / README.md
Created February 10, 2016 14:20 — forked from dciccale/README.md
Cross-browser triggerEvent function done with 127 bytes of JavaScript

triggerEvent

Cross-browser function to trigger DOM events.

@hsnaydd
hsnaydd / vanilla-ajax-request.js
Created February 7, 2016 17:13
Vanilla Ajax Request
// Modified from source: http://stackoverflow.com/a/18078705/772086
var ajax = {};
ajax.x = function () {
if (typeof XMLHttpRequest !== 'undefined') {
return new XMLHttpRequest();
}
var versions = [
"MSXML2.XmlHttp.6.0",
"MSXML2.XmlHttp.5.0",
@hsnaydd
hsnaydd / debounce.js
Created January 26, 2016 12:20
Javascript debounce function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
function includes(array, obj) {
return Array.prototype.indexOf.call(array, obj) != -1;
}
function arrayRemove(array, value) {
var index = array.indexOf(value);
if (index >= 0) {
array.splice(index, 1);
}
return index;
@hsnaydd
hsnaydd / media-queries-mixin.scss
Created October 14, 2015 06:44
Media Queries Mixin
@mixin breakpoint($point) {
@if ($MQs == true) {
@if $point == baby-bear {
@media (max-width: 500px) { @content; }
}
@if $point == mama-bear {
@media (max-width: 700px) { @content; }
}
@if $point == papa-bear {
@media (max-width: 800px) { @content; }
@hsnaydd
hsnaydd / named-media-queries.scss
Last active September 12, 2015 07:47
Named media Queries
// More : http://davidwalsh.name/write-media-queries-sass
@mixin breakpoint($point) {
@if $point == tablet {
@media (min-width: 768px) and (max-width: 1024px) {
@content;
}
} @else if $point == phone {
@media (max-width: 767px) {
@content;
}
@hsnaydd
hsnaydd / calculating-color-contrast.js
Created August 17, 2015 11:46
Calculating Color Contrast
/**
* Resource
* https://24ways.org/2010/calculating-color-contrast
*/
function getContrastYIQ(hexcolor){
var r = parseInt(hexcolor.substr(0,2),16);
var g = parseInt(hexcolor.substr(2,2),16);
var b = parseInt(hexcolor.substr(4,2),16);
var yiq = ((r*299)+(g*587)+(b*114))/1000;
@hsnaydd
hsnaydd / doThousands.js
Created July 7, 2015 09:26
Binler basamaklarını nokta ile ayırma
function doThousands(n) {
n = '' + n;
if (n.length < 4) return n;
var c = n.length % 3;
var pre = n.substring(0, c);
return pre + (pre.length? ',' : '') + n.substring(c).match(/\d{3}/g).join(',');
}
function doThousandsRegExp(n) {
if (n.length < 4) return n;