Skip to content

Instantly share code, notes, and snippets.

View Sanix-Darker's full-sized avatar
🐼
coding in the dark...

darker Sanix-Darker

🐼
coding in the dark...
View GitHub Profile
@Sanix-Darker
Sanix-Darker / SummerNote(With file in the text, content [Images or Videos])
Created September 9, 2017 09:26
SummerNote(With file in the text, content [Images or Videos])
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.7/summernote.css" rel="stylesheet">
<div class="summernote"></div>
<textarea name="summerNoteContent" id="resultSummerNote" required=""></textarea>
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.7/summernote.js"></script>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
@Sanix-Darker
Sanix-Darker / Simple upload file
Created September 9, 2017 10:39
Simple upload file
$file='';
if(isset($_FILES['img']) AND $_FILES["img"]['size']<=10000000 AND $_FILES["img"]['size']>100){
$folder = '../images/blog/';
$tmp_name = $_FILES["img"]["tmp_name"];
$name = $_FILES["img"]["name"];
$img = pathinfo($_FILES["img"]['name']);
$file = "blog_".rand(0,999999).$name;
move_uploaded_file($tmp_name, $folder.$file);
}
@Sanix-Darker
Sanix-Darker / Resize image to multiple dimensions (PHP)
Created September 9, 2017 10:56
Resize image to multiple dimensions (PHP)
$valid_formats = array("jpg", "png", "gif", "bmp");
$max_file_size = 1024*7500; //100 kb
$path = "assets/img/photo/"; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
@Sanix-Darker
Sanix-Darker / [PHP] Get IP adress of the visitor
Last active September 23, 2017 20:46
[PHP] Get IP adress of the visitor
<?php
/**
* Ensures an ip address is both a valid IP and does not fall within
* a private network range.
*/
function validate_ip($ip)
{
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
return false;
}
@Sanix-Darker
Sanix-Darker / [JS] How to check if jQuery is not already, loaded and call it
Last active September 23, 2017 20:47
[JS] How to check if jQuery is not already, loaded and call it
function myJQueryCode() {
//Do stuff with jQuery
}
if(typeof jQuery=='undefined') {
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = 'jquery.js';
jqTag.onload = myJQueryCode;
@Sanix-Darker
Sanix-Darker / [PHP] Force a download of a file
Last active September 23, 2017 20:47
[PHP] Force a download of a file
<?php
if(isset($_REQUEST['src'])){
$file_name = $_REQUEST['src'];
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$file_name."\"");
readfile('../Your_Path_Here/'.$file_name);
exit;
}
?>
@Sanix-Darker
Sanix-Darker / [JS] Using the core $.ajax() method
Last active September 23, 2017 20:49
[JS] Using the core $.ajax() method
// Using the core $.ajax() method
$.ajax({
// The URL for the request
url: "post.php",
// The data to send (will be converted to a query string)
data: {
id: 123
},
// Whether this is a POST or GET request
type: "GET",
@Sanix-Darker
Sanix-Darker / [PHP] Check the current link URI and do action
Last active September 23, 2017 20:49
[PHP] Check the current link URI and do action
@Sanix-Darker
Sanix-Darker / [CSS] Nice box Shadows
Created September 23, 2017 20:45
[CSS] Nice box Shadows
.top-box
{
box-shadow: inset 0 7px 9px -7px rgba(0,0,0,0.4);
}
.left-box
{
box-shadow: inset 7px 0 9px -7px rgba(0,0,0,0.4);
}
.right-box
{
@Sanix-Darker
Sanix-Darker / [Ruby] loop Iterraors
Created September 29, 2017 18:14
[Ruby] loop Iterraors
#!/usr/bin/ruby
## Count to 50
1.upto(50) {|n| puts n}
## Count Down to 1
50.downto(1) {|n| puts n}
## Count to 20
(1..20).each {|n| puts n}