Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / messages table
Last active September 23, 2016 06:41
+------+----------+-----------------+-----------------+-------------+-------------+----------------------+---------------------+
| id | body | recipientId | recipientType | senderId | status | dateReceived | dateSent |
+------+----------+-----------------+-----------------+-------------+-------------+----------------------+---------------------+
| 1 | mEssAgE | 2 | user | 5 | pending | 2016-09-22 20:22:05 | 2016-09-22 20:22:05 |
| 2 | test123 | 3 | room | 4 | received | 2016-09-22 20:22:05 | 2016-09-22 20:22:05 |
+------+----------+-----------------+-----------------+-------------+-------------+----------------------+---------------------+
@mr5z
mr5z / get-user-by-id.php
Last active July 5, 2017 08:30
get user by id
<?php
function getUserById($userId) {
$sql = "SELECT users.*,
COALESCE((SELECT locations.friendlyAddress
FROM locations
WHERE locations.userId = users.id
ORDER BY locations.dateGather
DESC LIMIT 1), 'Unavailable') lastKnownLocation,
COALESCE((SELECT CONCAT(locations.latitude, ',', locations.longitude)
FROM locations
class Http {
public:
// omitted other code
/**
* @param callback(CURLcode, response)
*/
template<typename F>
void request(std::string url, F &callback) {
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/settings_category_title_server"
android:key="@string/settings_key_title_server">
<EditTextPreference
android:key="@string/settings_key_server_address"
android:summary="@string/settings_summary_server_address"
// ----------------
// ---------------- Usage
// ----------------
public void newRequest(String memberToken, String accessKey) {
OkHttpClient client = defaultHttpClient();
Request request = new Request.Builder()
.url(url)
.addHeader("accesskey", accessKey)
.addHeader("membertoken", memberToken)
@mr5z
mr5z / BindableExtension.cs
Last active September 29, 2020 10:49
Shortened or lessen the input parameter to Xamarin.Forms.BindableProperty.Create()
public static BindableProperty CreateProperty<T>(T defaultValue = default, BindingMode mode = BindingMode.TwoWay, [CallerMemberName] string propertyName = null)
{
propertyName = RemoveLastOccurrence(propertyName, "Property");
return BindableProperty.Create(propertyName, typeof(T), typeof(BindableObject), defaultValue, mode);
}
private static string RemoveLastOccurrence(string source, string toFind)
{
var index = source.LastIndexOf(toFind);
return index == -1 ? source : source.Substring(0, index);
@mr5z
mr5z / test.cs
Created July 5, 2017 08:14
C# pattern type matching
if (string.Empty is object a)
{
return;
}
//a = ""; // uncomment this line to compile
switch(a)
{
case string b:
@mr5z
mr5z / a.regex
Last active July 6, 2017 10:16
regex
BindableProperty\.Create
< // begin of template
\s*? // optional spaces
[a-zA-Z0-9\.]+ // matches letters and numbers including dots
, // literal comma
\s*? // optional spaces
([a-zA-Z0-9\.\?<>]+) // matches letters, numbers, dots, greater/less than signs, question marks - first group
> // end of template
\s*? // optional spaces
\( // begin of function invoke i.e open parenthesis
@mr5z
mr5z / popups.js
Created September 6, 2017 02:57
lorem ipsum popups
function createPopup(e){var t=document.createElement("div");t.style.width="400px",t.style.height="180px",t.style.padding="40px 18px",t.style.backgroundColor="#555",t.style.color="white",t.style.position="absolute",t.style.left=rand(20,400)+(window.innerWidth/2-200)+"px",t.style.top=rand(20,200)+(window.innerHeight/2-90)+"px",t.style.zIndex="1000",t.style.transition="background-color 6s ease-out",t.className="x-popup";var o=document.createTextNode(e);return t.appendChild(o),t}function rand(e,t){return[-1,1][2*Math.random()|0]*Math.floor(Math.random()*(t-e+1)+e)}!function(){var e=0;setInterval(function(){e++;var t=createPopup("Lorem Ipsum");document.body.appendChild(t),setTimeout(function(){t.style.backgroundColor="rgba(0, 0, 0, 0)"},100),setTimeout(function(){document.body.removeChild(t)},6e3)},1e3)}();
@mr5z
mr5z / screensaver.js
Last active January 3, 2018 14:21
not really my code
!function(t,e){var i=document.createElement("canvas");i.id="world",i.style.backgroundColor="transparent",i.style.zIndex="10000",i.style.width=window.innerWidth+"px",i.style.height=window.innerHeight+"px",i.style.position="fixed",i.style.left="0",i.style.top="0",i.style.pointerEvents="none",document.body.appendChild(i);var h=30,s=300,o=3,r=10,n=4e3,a=.5,c=function(t,e){var i,h,s,o,r=null;return function(){if(null!==r)return o=r,r=null,h*o+t;do{i=2*Math.random()-1,h=2*Math.random()-1,s=i*i+h*h}while(s>=1);return r=e*Math.sqrt(-2*Math.log(s)/s),i*r+t}};pointCopy=function(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e},Trail=function(t,e,i){this.pos={x:0,y:0,z:0},this.start={x:0,y:0,z:0},this.goal={x:0,y:0,z:0},this.anchor_1={x:0,y:0,z:0},this.anchor_2={x:0,y:0,z:0},this.start_time=0,this.take_time=1,this.vertexes=[],this.anchors_1=[],this.anchors_2=[],this.color_f=i,pointCopy(t,this.pos),pointCopy(t,this.start),pointCopy(t,this.goal),this.setNextGoal(e)},Trail.prototype.setNextGoal=function(t,e){pointCopy(this.goal,this.