Skip to content

Instantly share code, notes, and snippets.

View bertrand-lupart's full-sized avatar

Bertrand Lupart bertrand-lupart

View GitHub Profile
@bertrand-lupart
bertrand-lupart / send-text.scpt
Created September 30, 2022 09:30
AppleScript to send a SMS from a Mac using Handoff / Continuity
-- This script allows to programmatically send a SMS from a Mac using an iPhone carrier plan
-- Requirements :
-- * iPhone running iOS 8.1+ with a proper carrier plan
-- * Mac running macOS 10.10+
-- * Message forwarding should be properly configured on both devices. See
-- https://support.apple.com/en-gb/HT208386
-- Usage :
-- This script should be invoqued via Terminal with the osascript command :
@bertrand-lupart
bertrand-lupart / writeln.pike
Created August 12, 2022 15:59
Pike writeln()
# Easily code your writeln() Pike function
int writeln(string fmt, mixed ... args)
{
fmt += "\n";
write(fmt, @args);
return 0;
}
@bertrand-lupart
bertrand-lupart / Time.pmod
Last active October 18, 2019 07:02
Breaking the 838:59:59 limit of MySQL's SEC_TO_TIME() and TIME_TO_SEC() with Pike
// Breaking the 838:59:59 limit of MySQL's SEC_TO_TIME() and TIME_TO_SEC()
//! @param seconds
//! The number of seconds to convert to time
//! @return
//! Seconds converted to time (123:45:67) as a string, -1 if failed
int|string sec_to_time(int _seconds)
{
int seconds = (int)_seconds;
@bertrand-lupart
bertrand-lupart / Rand.pmod
Created July 9, 2019 16:25
Generate random printable strings using Pike
string random_printable_string(int size)
{
string rand = "";
for(int i=0; i<size; i++)
rand += String.int2char(random(94)+32);
return rand;
}
@bertrand-lupart
bertrand-lupart / encrypt_decrypt_cbc.pike
Created July 9, 2019 16:02
Simple symmetric encryption / decryption using AES CBC, pre-shared 16 bytes key and random 16 bytes initialisation vector
#!/usr/bin/pike
// Pre-shared key. Should be 16 bytes, kept secret
string key = "secret16byteskey";
// Message to encode
string msg_from = "What's your name, James?";
// Initialisation vector. Should be 16 bytes, randomly generated for each iteration
string iv = random_string(16);
int main(int argc, array(string) argv)
@bertrand-lupart
bertrand-lupart / encrypt_decrypt_ecb.pike
Last active July 9, 2019 16:05
Simple symmetric encryption / decryption using AES ECB and pre-shared 16 bytes key
#!/usr/bin/pike
// Pre-shared key. Should be 16 bytes, kept secret
string key = "secret16byteskey";
// Message to encode
string msg_from = "What's your name, James?";
int main(int argc, array(string) argv)
{
write("key : %O\nmsg : %O\n", key, msg_from);
@bertrand-lupart
bertrand-lupart / sub-second_epoch_hilfe.pike
Last active April 26, 2019 08:48
sub-second epoch Pike
> object t = System.Time(); t->sec; t->usec; t->usec_full;
(1) Result: 1556201631
(2) Result: 393431
(3) Result: 1556201631393970
> object s = Calendar.parse("%Y-%M-%aT%h:%m:%s.%f","2019-04-25T15:10:03.193000+00:00");
> s->f_unix_time();
(1) Result: 1556197803.193
@bertrand-lupart
bertrand-lupart / extensions-dynamic-conferences-meetme-to-confbridge.conf
Last active April 26, 2019 09:13
Asterisk extensions.conf fragment implementing MeetMe()'s dynamic pin-protected conferences using ConfBridge()
; You may miss MeetMe() from your old asterisk box
; Here's an asterisk fragment whose goal is to mimic the following MeetMe() line using Confbridge()
; exten => 42,1,MeetMe(,cIxDsM)
; call 42 to create/join dynamic pin-protected ConfBridge() conference
; adapt context and call number to your actual numbering plan
[your-random-context]
exten => 42,1,NoOp()
same => n,Goto(conference,s,1)
same => n,Hangup()
@bertrand-lupart
bertrand-lupart / how_many_days_since.pike
Created November 8, 2018 16:38
How many days since…
(Calendar.dwim_day("2001-02-12")->distance(Calendar.now())->how_many(Calendar.Day));
@bertrand-lupart
bertrand-lupart / csv_trim_all_whites.pike
Last active April 26, 2019 09:08
Pike script which trim all whites in CSV data
#!/usr/bin/env pike
// This script take a dirty CSV as input
// Output a white-trimed CSV : spaces, tabs, CR, LF
// Set up the following
string in_dirty_path = "";
string out_clean_path = "";
int i_ve_set_file_paths = 0;