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");
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Anaconda\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Anaconda\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Anaconda\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Anaconda\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
@ruliarmando
ruliarmando / dynamic-method.php
Created October 29, 2014 08:55
php dynamic method addition
<?php
class Foo
{
private $dynamicMethods = array();
public function __call($name, $arguments=array())
{
if(isset($this->dynamicMethods[$name]) and is_callable($this->dynamicMethods[$name])){
call_user_func_array($this->dynamicMethods[$name], $arguments);
@ruliarmando
ruliarmando / cek_string2.py
Created October 23, 2014 16:30
cek string version 2
from collections import Counter
def cek(string):
if len(string) >= 2:
return True if sum([1 for i in Counter(string).most_common() if i[1] >= 2]) >= 2 else False
return False
print cek('aaabbcdeg')
print cek('aaaaaaaaab')
print cek('absjedeo')
print cek('aaaabbbbbccccdd')