Skip to content

Instantly share code, notes, and snippets.

View amiraliakbari's full-sized avatar

AmirAli Akbari amiraliakbari

View GitHub Profile
@amiraliakbari
amiraliakbari / TrxMultiSend.sol
Created October 27, 2020 13:44
Tron Multi-send contract
pragma solidity ^0.5.0;
/**
* SPDX-License-Identifier: UNLICENSED
*/
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
@amiraliakbari
amiraliakbari / main.css
Created April 29, 2018 13:38
Slack Persian Fix
@font-face {
font-family: 'IRANSans';
src : url("https://ir-cloud.ir/fonts/IRANSansFaNum/eot/IRANSansWeb(FaNum).eot"), url('https://ir-cloud.ir/fonts/IRANSansFaNum/woff/IRANSansWeb(FaNum).woff') format('woff'), url('https://ir-cloud.ir/fonts/IRANSansFaNum/ttf/IRANSansWeb(FaNum).ttf') format('truetype'), url("https://ir-cloud.ir/fonts/IRANSansFaNum/woff2/IRANSansWeb(FaNum).woff2") format('woff2');
}
.c-message {
font-family: 'IRANSans', 'B Nazanin';
}
.c-message__content {
@amiraliakbari
amiraliakbari / proxy.pac
Last active September 16, 2017 06:54
Proxy Auto Configuration
/**
* Proxy auto configuration file for accessing sites blocked in Iran due to
* sanctons or filtering. To use, a socks5 proxy must be running and accessible
* on localhost port 1080. Set url of this gist in "Automatic proxy configuration URL"
* field in "Network Proxy Settings" in Firefox.
*/
function FindProxyForURL(url, host) {
var blockedHosts = [
'twitter.com', 'twimg.com', // Twitter
@amiraliakbari
amiraliakbari / a.txt
Created April 28, 2017 13:43
Bash Useful Gists
I have marked with a * those which I think are absolutely essential
Items for each section are sorted by oldest to newest. Come back soon for more!
BASH
* In bash, 'ctrl-r' searches your command history as you type
- Input from the commandline as if it were a file by replacing
'command < file.in' with 'command <<< "some input text"'
- '^' is a sed-like operator to replace chars from last command
'ls docs; ^docs^web^' is equal to 'ls web'. The second argument can be empty.
* '!!:n' selects the nth argument of the last command, and '!$' the last arg
@amiraliakbari
amiraliakbari / get_plan_score
Created April 28, 2017 13:41
Large SQL Examples
CREATE OR REPLACE FUNCTION get_plan_score(faculty_id integer, from_date date, until_date date)
RETURNS TABLE(
fdate date ,
udate date ,
score int ) AS
$BODY$
DECLARE res integer;
DECLARE unit integer;
DECLARE StartDate DATE;
DECLARE EndofYear DATE;
@amiraliakbari
amiraliakbari / xlsx.py
Created January 6, 2016 13:21
ensure_elementtree_imported
ET = None
ET_has_iterparse = False
def ensure_elementtree_imported(verbosity, logfile):
global ET, ET_has_iterparse
if ET is not None:
return
if "IronPython" in sys.version:
import xml.etree.ElementTree as ET
#### 2.7.2.1: fails later with
@amiraliakbari
amiraliakbari / XKB IR Keyboard
Last active July 26, 2022 11:58
XKB Customized Persian Keyboard Layout
// Iranian keyboard layout
// Replace with "/usr/share/X11/xkb/symbols/ir"
// Customized Version
////////////////////////////////////////
// Persian layout,
// based on
// Information Technology – Layout of Persian Letters and Symbols on Computer Keyboards
// ISIRI 9147 – 1st Edition
@amiraliakbari
amiraliakbari / a.py
Created October 3, 2015 07:48
Refactoring Exercise
def get_page_from_queue():
pages = Page.objects.filter(username=q_key)
if pages:
page = pages[0]
setattr(page, 'priority', q_value)
page.save()
else:
pq = PageQueue(username=q_key, priority=q_value)
pq.save()
@amiraliakbari
amiraliakbari / rename_traces.py
Created April 16, 2015 13:45
Fix special characters in filenames
#!/usr/bin/env python
def rr(dir):
for d in os.listdir(dir):
dd = d.replace('\xef\x80\xa2', '-')
if d != dd:
os.rename(os.path.join(dir, d), os.path.join(dir, dd))
child = os.path.join(dir, dd)
if os.path.isdir(child):
@amiraliakbari
amiraliakbari / is_binary.c
Last active April 14, 2020 18:45
Interview Code Reading Questions
static void gather_stats(const char *buf, unsigned long size, struct text_stat *stats)
{
unsigned long i;
memset(stats, 0, sizeof(*stats));
for (i = 0; i < size; i++) {
unsigned char c = buf[i];
if (c == '\r') {
stats->cr++;