Skip to content

Instantly share code, notes, and snippets.

@yfktn
yfktn / osticket_daftar.sql
Last active August 27, 2021 08:24
OSTicket Ambil daftar tiket dan siapa yang meminta
select tt.created, tt.number, ht.topic, tc.subject, ts.name as 'STATUS', u.name, uc.phone, ue.address from ost_thread t
inner join ost_ticket tt on t.id = tt.ticket_id
inner join ost_ticket__cdata tc on tc.ticket_id = tt.ticket_id
inner join ost_ticket_status ts on ts.id = tt.status_id
inner join ost_user u on tt.user_id = u.id
inner join ost_user__cdata uc on uc.user_id = u.id
inner join ost_user_email ue on ue.user_id = u.id
inner join ost_help_topic ht on ht.topic_id = tt.topic_id
where t.object_type = 'T'
-- and tt.number = 506581
@yfktn
yfktn / generate-kode-booking.php
Created March 19, 2020 13:31
Cara bikin kode booking
// di suatu fungsi pada sebuah model booking
protected function generateKodeBooking()
{
$penyewa = $this->penyewa_id;
$disewa = $this->disewa_id;
// dapatkan random char sebanyak 5 buah
// https://stackoverflow.com/questions/5438760/generate-random-5-characters-string
$rndchar = substr(str_shuffle(str_repeat("123456789ABCDEFGHJKLMNPQRSTUVWXYZ", 5)), 0, 5);
return sprintf("%s%d%d", $rndchar, $penyewa, $disewa);
}
@yfktn
yfktn / playground-concurency-exercise.go
Created April 19, 2018 08:14
Answer to Go Playground Exercise
// https://tour.golang.org/concurrency/8
package main
import "golang.org/x/tour/tree"
import "fmt"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
// we need to close channel, so it need to call separately
recursiveWalk(t, ch)
func longestPalindrome(s string) string {
start, end := 0, 0
part := 1
maxPal, maxStart, maxEnd := 0, 0, 0
lenS := len(s)
nowBreak := false
for i:=0;i<lenS;i++ {
// looping for first try, the even pal
for {
if i - part < 0 || i + part >= lenS {
@yfktn
yfktn / palindrom.go
Created April 10, 2018 06:34
Palindrom atau tidak
package main
import (
"fmt"
)
func main() {
test := "able was i ere i saw elba"
testBalik := reverseString(test)
if test == reverseString(test) {
@yfktn
yfktn / gist:9705467cde930716d536
Created October 13, 2014 05:24
JS Script to automatically set menu as active in the bootstrap nav
$('ul.nav a[href="' + window.location + '"]').parent().addClass('active');
@yfktn
yfktn / get_post_belongs_to_category.php
Created April 7, 2014 03:01
Get all Posts that are belongs to a category ...
/**
* assume Post has belongsToMany relationship with Category, and Category has belongsToMany relationship with Post named posts
*
* we need to get all posts that belongs to a category ...
*/
$posts = Category::find($idCategory)->posts()->get();
// test
foreach($posts as $p)
{
@yfktn
yfktn / ModelSlug.php
Created April 4, 2014 06:25
The trait use when we need function like Model::findOrFail(), but it used for slug. Or even the other field?
namespace app\lib\ModelSlug;
/**
* Imagine we have Category and Post, and we want to search for Post that are in Category, using a slug
* of Category.
*
* In controller ...
*
* $posts = Category::findSlugOrFail($theSlugFromRoute, $the_slug_field)->posts()->get();
*
* If failed, it will throw the same exception as findOrFail did.
@yfktn
yfktn / html-macro-breadcrumbs.php
Last active August 29, 2015 13:58
Laravel 4 HTML Macro to Generate Breadcrumbs
/**
* Laravel 4.1 HTML Macro to generate breadcrumbs!
*
* Use it to generate breadcrumbs that compatible with Bootstrap 3.
*
* To use it you need to pass value through $arrayLinks with array that contains
* named keys and it value. Key would be the label of breadcrumbs and value
* would be the link. If we don't pass the named key then it would be label without
* link attached.
*