Skip to content

Instantly share code, notes, and snippets.

View ruliarmando's full-sized avatar
🎮
Playing

Rully Ramanda ruliarmando

🎮
Playing
View GitHub Profile
@ruliarmando
ruliarmando / autocomplete.blade.php
Created March 3, 2021 10:34
Select2 Ajax Livewire Integration
@props(['url', 'field', 'error', 'selected' => null, 'extra' => null])
<div wire:ignore>
<select {{ $attributes->merge(['style' => 'width:100%', 'class' => 'mt-1 block w-full py-2 px-3 bg-white rounded-md shadow-sm focus:outline-none
sm:text-sm'])->except('wire:model') }}>
@if ($selected)<option value="{{ $selected[0] }}" selected="selected">{{ $selected[1] }}</option>@endif
</select>
</div>
@if (!empty($error))<span class="text-red-500 text-sm">{{ $error }}</span>@endif
import { useState, useEffect } from 'react';
import api from 'utils/api';
const useFecth = (url, params) => {
const [response, setResponse] = useState(null);
const [error, setError] = useState(null);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
@ruliarmando
ruliarmando / promise-all-object.js
Created March 28, 2019 02:33
Like Promise.all but with object (must use lodash)
Promise.allValues = async (object) => {
return _.zipObject(_.keys(object), await Promise.all(_.values(object)))
}
@ruliarmando
ruliarmando / memoize.js
Last active September 9, 2018 14:27
A naive implementation of memoize function in Javascript
const memoize = function(f) {
let cache = {};
return function(...args) {
const arg_str = JSON.stringify(args);
cache[arg_str] = cache[arg_str] || f.apply(f, args);
return cache[arg_str];
}
}
@ruliarmando
ruliarmando / greaterThan.js
Created August 30, 2018 09:02
Dynamic greater than function factory
const greaterThan = (thisNumber) => (anotherNumber) => anotherNumber > thisNumber;
const greaterThan10 = greaterThan(10);
const greaterThan2 = greaterThan(2);
console.log('12 > 10 = ', greaterThan10(12)); // 12 > 10 = True
console.log('8 > 10 = ', greaterThan10(8)); // 8 > 10 = False
console.log('3 > 2 = ', greaterThan2(3)); // 3 > 2 = True
from random import choice
from string import ascii_lowercase, ascii_uppercase, digits
from tkinter import Tk, Entry, Button, StringVar
def random_string(length):
return ''.join(choice(ascii_lowercase + digits + ascii_uppercase) for i in range(length))
root = Tk()
root.title('32 chars random string generator')
<?php
/* index.html */
class __TwigTemplate_37a968442c22648ceb4a16069820cc5350b97e50f45f26c5442d7c036ad743d2 extends Twig_Template
{
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this->parent = $this->env->loadTemplate("base.html");
import datetime
month_placeholder = {
'Jan' : 1,
'Feb' : 2,
'Mar' : 3,
'Apr' : 4,
'Mei' : 5,
'Jun' : 6,
'Jul' : 7,
@ruliarmando
ruliarmando / EWebUser.php
Created November 30, 2013 04:30
WebUser component (Yii Framework)
<?php class EWebUser extends CWebUser{
// ini buat pengecekan level akses tiap user
function getLevel(){
$level = Yii::app()->user->getState('level');
return $level;
}
function isAdmin(){ // apakah user adalah admin?
return Yii::app()->user->getState('level') == 1;
@ruliarmando
ruliarmando / transform.php
Created November 27, 2013 13:33
transform numbers into string
<?php
function transform($numbers){
$rules = [
1 => 'a',
2 => 'b',
3 => 'c',
4 => 'd',
5 => 'e',
6 => 'f',