Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@kosinix
kosinix / gitgotcha.md
Created December 18, 2017 08:00
git gotcha

Save vim commit message

Press ESC to make sure you are out of the edition mode and then type:

:wq

Delete remote branch

@kosinix
kosinix / gotcha.js
Last active October 29, 2017 08:51
JS promise API gotchas
function errorFunction(){
return Promise.reject('Reject value.');
}
function goodFunction(error=false){
return Promise.resolve('Resolved value.');
}
// Example 1. One level
goodFunction().then(function(ok){
console.log('First "then" called. Value: ', ok);
@kosinix
kosinix / excerpt.php
Created June 29, 2017 04:51
Read more that ends in sentence or exact words.
<?php
add_filter( 'the_content', 'my_the_content_filter', 22 );
function my_the_content_filter( $content ) {
if ( is_home() || is_archive() || is_search() ){
// Mode word
$mode = 'sentence'; // word or sentence
$count = 11;
/*
Theme Name: Turbo Surfing
Theme URI: #
Author: Team Perth
Author URI: #
Description: A theme for turbosurfing.com.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: turbosurfing
@kosinix
kosinix / Calendar formulas
Last active June 9, 2017 07:39
Formula for displaying days in a Gregorian calendar month
prefixLength - The number of pads before the first calendar day
suffixLength - The number of pads after the last calendar day
monthFirstWeekDay - The weekday of first month day. int 0-6 where 0 is Sunday and 6 is Saturday
monthLastWeekDay - he weekday of last month day. int 0-6 where 0 is Sunday and 6 is Saturday
calendarWeekStart - The weekday to which the calendar days start. int 0-6 where 0 is Sunday and 6 is Saturday
Pseudocode:
prefixLength = monthFirstWeekDay - calendarWeekStart
@kosinix
kosinix / doc.md
Last active April 20, 2017 07:44
Cycle2 event order of exec

Init

  • cycle-bootstrap
  • cycle-slide-added
  • cycle-pre-initialize
  • cycle-initialized
  • cycle-post-initialize
  • cycle-update-view

Transition

@kosinix
kosinix / minmax.css
Created March 15, 2017 17:40
CSS min-width vs max-width
@media screen and (min-width:100px) { /* Screen >= 100 */
body { font-weight:bold; }
}
@media screen and (min-width:200px) { /* Screen >= 200 */
body { color:#555; }
}
@media screen and (max-width:100px) { /* Screen <= 100 */
body { font-weight:bold; }
@kosinix
kosinix / customevents.js
Created January 29, 2017 03:39
Create custom event in plain JS. Supports modern browsers (IE11+)
// IE >= 11
function triggerEvent(el, eventName, options) {
var event,
opts = {detail: options};
event = newEvent(eventName, opts);
el.dispatchEvent(event);
}
function newEvent(eventName, options) {
@kosinix
kosinix / rust.md
Last active December 18, 2016 12:01
Rust primitive types range on 64 bit system
type min max
i8 -128 127
i16 -32768 32767
i32 -2147483648 2147483647
i64 -9223372036854775808 9223372036854775807
u8 0 255
u16 0 65535
u32 0 4294967295
u64 0 18446744073709551615
@kosinix
kosinix / phpgotchas.md
Last active September 19, 2016 08:30
PHP Gotchas

SplPriorityQueue Does Not Behave Like a Queue

SplPriorityQueue is advertised as a prioritized queue. Ideally, as a queue, when adding items of the same priority, the items should retain the same order as how they were registered (FIFO). In PHP the order is unexpected:

<?php
$queue = new SplPriorityQueue();
$queue->insert('1',0);
$queue->insert('2',0);
$queue->insert('3',0);

$queue->insert('4',0);