-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.ls
267 lines (210 loc) · 6.92 KB
/
functions.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
@SiteQ =-> /^[\S]+\.[\S]+$/gi.test it
@IntQ =-> /^[0-9\.]+$/gi.test it
@EthQ =-> /^(0x)?[0-9a-zA-Z]{42}$/i.test it
@EmailQ =-> /^[\S]+\@[\S]+\.[\S]+$/gi.test it
@date-now-arr =->
new Date(Date.now!)
|> String
|> split ' '
|> slice 1 4
@date-tomorrow-arr =-> inc-date-arr {date:Date.now!, inc:1}
@inc-date-arr =->
date = new Date(Date.parse it.date)
new Date(date.currentID(date.getDate() + (+it.inc-1)))
|> String
|> split ' '
|> slice 1 4
@today =-> format-date date-now-arr!
@tomorrow =-> format-date date-tomorrow-arr!
@inc-date =-> format-date inc-date-arr it
@get-all-of =->
rules_arr = []
rules = state.get it
for n of rules
rule = rules[n]
rule.id = n
rules_arr.push rule
rules_arr
@get-num-of =->
arr = []
els = state.get it
for n of els
arr.push n
arr
@delete-year =-> slice 0 6 it
@get-id =->
id = ''
charset = union [48 to 57], [65 to 90],[97 to 122]
for i in [1 to 30]
pos = Math.floor(62*Math.random!)
id += String.fromCharCode charset[pos]
return String(id)
@push-to-state =->
current = state.get &0
current.push &1
state.set &0, current
@lookup-and-append = (obj,cls) ~> Meteor.setTimeout((~>
if typeof obj != \undefined => $(cls).html(String(obj))
else lookup-and-append(obj,cls); #console.log obj
), 30)
@lookup= (obj,func) ~> Meteor.setTimeout((~>
if typeof obj != \undefined => func(obj);
else
state.set(\inc_lookup (state.get(\inc_lookup)||1)+1)
console.log state.get(\inc_lookup)
if state.get(\inc_lookup) > 20 => return #location.reload()
lookup(obj,func)
), 30)
@conscb =->
if &0 => console.log \err: &0
if &1 => console.log \res: &1
@goto-success-cb =->
if &0 => console.log \err: &0
if &1
console.log \res: &1
Router.go \success
@simple-cb =->
if &0 => new Error &0
if &1 => &1
@big-zero = \0x0000000000000000000000000000000000000000
@get-it-tail =->
it|> join '' |> chars |> tail
@get-it-head =->
it|> join '' |> chars |> first
@get-num =->
( [get-it-head(it)] ++ ['.'] ++ get-it-tail(it) )|> join ''
@eth-to-wei =(str)->
bn = new BigNumber(str)
bn.times(1000_000_000_000_000_000).to-fixed!
@bigNum-add =(arr1,arr2)->
a1 = new BigNumber(0)
a2 = new BigNumber(0)
a1.c = arr1?c
a1.e = arr1?e
a1.s = arr1?s
a2.c = arr2?c
a2.e = arr2?e
a2.s = arr2?s
bigNum-toStr a1.add a2
@bigNum-toStr =(arr)->
bn = new BigNumber(0)
bn.c = arr?c
bn.e = arr?e
bn.s = arr?s
many = 1000_000_000_000_000_000
bn.divided-by(many).to-fixed!
# console.log \bn: bn
@lilNum-toStr =(arr)->
bn = new BigNumber(0)
bn.c = arr?c
bn.e = arr?e
bn.s = arr?s
bn.to-fixed!
@state-null =-> state.set it, null
@shortest =(str1, str2)->
if str1.length > str2.length => str2
else str1
@yesno =-> if it then \Yes else \No
@lorem =-> 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus posuere est in lacus varius congue. Etiam vitae nunc consequat, porttitor odio a, molestie quam. Pellentesque blandit ac diam sed finibus. Sed libero est, molestie sed euismod at, posuere quis nisl. Praesent enim purus, efficitur quis mollis nec, accumsan vel ante. Phasellus aliquet vel nulla a aliquam. Aliquam rutrum feugiat fermentum. Suspendisse semper ultrices metus, ut convallis enim posuere a. Nunc volutpat felis sed dictum aliquam. Aliquam ipsum mauris, cursus volutpat tincidunt id, semper ac metus. Maecenas pulvinar pellentesque nibh at mattis. Donec ut libero iaculis, pretium ipsum et, euismod neque. Sed varius lorem vel posuere aliquam. Maecenas elementum congue leo, quis condimentum tortor lacinia rutrum.'
@address-last =->
Router.current!originalUrl |> split \/ |> last
@address-prelast =->
Router.current!originalUrl |> split \/ |> initial |> last
@Jstr =-> JSON.stringify it
@mark =->
if it => i class:'large green checkmark icon'
else i class:'large grey minus icon'
@info-message =-> D 'ui message',
i class:'close icon'
i class:'book icon'
b &0
p &1
@simple-card-field=-> D 'ui fluid labeled input',
D 'ui label', &0
input style:'text-align:right' type:\text disabled:true value:&1
@get-route-name =-> Router.current!route?getName!
@todayMDY =-> join ' ' slice 1,4 split ' ' String(new Date Date.now!)
@format-date =-> join ' ' slice 1,4 split ' ' String(new Date it)
@loading-icon =-> i class:'ui wait icon' style:'margin:0px; font-size:11px'
@template-manager =-> switch it.type
case \admin
if it.usr == null => msg \Error 'Access denied. '
else if typeof it.usr?isAdmin is \undefined then return loading!
else if !it.usr?isAdmin => return msg \Error 'Access denied'
else it.template
case \load
if it.test! => it.template
else loading!
@spinner =-> d \ui.active.mini.inline.loader
@page-card=-> d \.section-form,
div class:"section-title #{if typeof &2 != \undefined => &2 }", &0
&1
@voteAccepted-cb=(err,res)->
if err => alert \Error: + JSON.stringify err
if res => Router.go \/voteAccepted
@stat-item=-> d \.stat-item,
d \.first &0
d \.second &1
@num-convert=->
it = +it
# if it < 0.01 => return "#{10000*it}milli"
if (it >= 1000) && (it < 1000000) => return "#{it/1000}K"
else if (it >= 1000000) => return "#{it/1000000}M"
else it
@shareOnFacebookLink=-> 'https://www.facebook.com/sharer/sharer.php?&u=' + window.location.href
@shareOnTwitterLink=-> 'https://twitter.com/intent/tweet?url=' + window.location.href + '&text=' + document.title
@shareOnGooglePlusLink=-> 'https://plus.google.com/share?url=' + window.location.href
@days-ago=->
date1 = new Date it
date2 = new Date Date.now!
timeDiff = Math.abs(date2.getTime() - date1.getTime())
diffDays = Math.floor(timeDiff / (1000 * 3600 * 24))
@dir-name=->
__meteor_bootstrap__.serverDir
|> split \/
|> take-while (-> it!= \.meteor)
|> join \/\
@get-nickname=(address)->
last-name = address |> drop 38 |> get-name
first-name = address |> drop 2 |> take 4 |> get-name
"#{first-name} #{last-name}"
@get-name=->
it
|> chars
|> map get-nickname-symbol
|> join ''
|> capitalize
@get-nickname-symbol=-> switch it
| \0 => \o
| \1 => \wan
| \2 => \too
| \3 => \fri
| \4 => \fo
| \5 => \fai
| \6 => \six
| \7 => \sev
| \8 => \eit
| \9 => \nain
| \a => \a
| \b => \bi
| \c => \ci
| \d => \di
| \e => \yea
| \f => \ef
@get-german-nickname-symbol=-> switch it
| \0 => \berg
| \1 => \ster
| \2 => \effer
| \3 => \mann
| \4 => \haus
| \5 => \witz
| \6 => \ner
| \7 => \hof
| \8 => \baum
| \9 => \ling
| \a => \zer
| \b => \sig
| \c => \schel
| \d => \schatz
| \e => \nitz
| \f => \tag