Skip to content

Instantly share code, notes, and snippets.

@niksudan
niksudan / box-sizing.css
Last active January 14, 2016 16:50
Width fix [CSS]
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@niksudan
niksudan / prime.clj
Last active January 7, 2016 20:11
Prime number checker [Clojure]
(defn prime? [n]
(loop [i 2]
(if (< i n)
(if (not (integer? (/ n i)))
(recur (+ i 1))
false
)
true
)
)
@niksudan
niksudan / index.js
Created December 1, 2015 19:04
Decimal calculator [JS]
var calculate = function(input)
{
var result = [], sum = 0;
input.forEach(function(element) {
sum += element;
});
input.forEach(function(element) {
result.push(element / sum);
@niksudan
niksudan / index.js
Created December 1, 2015 18:27
Array flattener [JS]
var flatten = function(array)
{
var result = [];
array.forEach(function(element) {
if (element instanceof Array) {
flatten(element).forEach(function(subElement) {
result.push(subElement);
}, this);
} else {
@niksudan
niksudan / index.php
Created November 20, 2015 20:00
Island generator [PHP]
<html>
<title>Island Generator</title>
<?php
include 'perlin.php';
$perlin = new Perlin();
$size = isset($_GET['size']) ? intval($_GET['size']) : 128;
if ($size > 512)
@niksudan
niksudan / cors.php
Created June 26, 2015 14:39
Cross Origin Permissions [PHP]
<?php
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // Cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
@niksudan
niksudan / api.php
Created June 26, 2015 14:36
Database Query Service [AngularJS]
<?php
$tables = array('settings', 'people', 'ratings', 'emails', 'comments', 'accounts');
define('ENTRY_LIMIT', 50);
/**
* method
* The operation you are about to perform
*
* table
@niksudan
niksudan / gulpfile.js
Last active August 29, 2015 14:23
Gulpfile [WordPress]
/**
* gulp-wordpress
* Nik Sudan
*
* Commands:
* gulp Build the files once
* gulp watch Watch for file changes and perform the correct tasks
* gulp styles Compiles SASS and injects the new CSS into your webpage
* gulp scripts Concats and uglifies js/src into one file
* gulp images Compresses images
@niksudan
niksudan / query.sql
Created June 26, 2015 14:20
MySQL user export [WordPress]
SELECT u.`user_login` as username, u.`display_name` as name, u.`user_email` as email
FROM wp_users u
INNER JOIN wp_usermeta m ON m.`user_id` = u.`ID`
WHERE m.`meta_key` = 'wp_capabilities'
AND (m.meta_value LIKE '%subscriber%')
ORDER BY u.`user_login`;
@niksudan
niksudan / .htaccess
Last active September 22, 2016 08:51
Local uploads folder [WordPress]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp-content/uploads/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://example.com/wp-content/uploads/$1 [L,P]
</IfModule>