Skip to content

Instantly share code, notes, and snippets.

View ricardoalcocer's full-sized avatar
💭
making music at https://alcomusic.com

Alco ricardoalcocer

💭
making music at https://alcomusic.com
View GitHub Profile
@ricardoalcocer
ricardoalcocer / jsxhr.js
Created October 17, 2020 21:26
JavaScript XHR
function xhr(method, uri, body, handler) {
var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
req.onreadystatechange = function ()
{
if (req.readyState == 4 && handler)
{
eval('var o=' + req.responseText);
handler(o);
}
}

RSA KEYS

If you haven't already got a ~/.ssh/id_rsa.pub on your computer, you'll need to generate one.

To generate key

ssh-keygen

To copy ssh key to your clipboard on a mac:

@ricardoalcocer
ricardoalcocer / gravatarfromemail.php
Created September 13, 2020 23:13
Get gravatar from email
<?php
$userMail = 'kevinrose@gmail.com';
$imageWidth = '150'; //The image size
$imgUrl = 'http://www.gravatar.com/avatar/'.md5($userMail).'fs='.$imageWidth;
echo "<img src=\"$imgUrl\">";
?>
@ricardoalcocer
ricardoalcocer / short-number-format.php
Created August 11, 2020 18:03 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@ricardoalcocer
ricardoalcocer / README.md
Created July 8, 2020 18:13
In PHP, take a query string and convert it into an SQL String

Sample usage

$qs = "?@fields=name,id&@where=name[ne]john+doe&@limit=0&@offset=100&@order=-timestamp";

$theClass = new queryStringToSQL('users'); // pass in the name of the table

$sqlString = $theClass->getSQLString($qs); // pass in the query string
@ricardoalcocer
ricardoalcocer / CountUpTimer.kt
Created May 13, 2020 04:36
Kotlin Android Countup
import android.os.CountDownTimer
abstract class CountUpTimer protected constructor(private val duration: Long) :
CountDownTimer(duration, INTERVAL_MS) {
abstract fun onTick(second: Int)
override fun onTick(msUntilFinished: Long) {
val second = ((duration - msUntilFinished) / 1000).toInt()
onTick(second)
}
@ricardoalcocer
ricardoalcocer / countdown.kt
Created May 13, 2020 04:34
Kotlin Android Countdown
private fun stopCountDown(){
val t = Toast.makeText(this,"Stopping countdown",Toast.LENGTH_SHORT).show()
timer1.cancel()
timer1IsRunning=false
}
private fun startCountDown(){
timer1 = object : CountDownTimer(duration, interval) {
override fun onFinish() {
txtTimer1.text = "0"
@ricardoalcocer
ricardoalcocer / timer.kt
Created May 13, 2020 04:32
Kotlin Android Timer
btnStartInfiniteTimer.setOnClickListener{
if (!isInfiniteTimerRunning){
infiniteTimer=Timer()
isInfiniteTimerRunning = true
infiniteTimer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
infiniteTimerTick()
}
}, 0, 1000)
}
@ricardoalcocer
ricardoalcocer / scripts.sh
Created April 24, 2020 17:26
Disable Mac Desktop icons
defaults write com.apple.finder CreateDesktop false
killall Finder
@ricardoalcocer
ricardoalcocer / data.json
Last active April 13, 2020 18:10
TempJSON
[
{
"id": "1",
"name": "John",
"email": "john@gmail.com",
"location": "Mexico"
},
{
"id": "2",
"name": "Peter",